Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error in VS2010 #510

Closed
Gitzzq opened this issue Aug 24, 2017 · 8 comments
Closed

Compilation error in VS2010 #510

Gitzzq opened this issue Aug 24, 2017 · 8 comments

Comments

@Gitzzq
Copy link

Gitzzq commented Aug 24, 2017

I am using VS2010 and tried to upgrade the code from 1.8 to 1.10, but lots of errors:
1> civetweb.c
1>d:\ xxx\civetweb.c(14682): error C2275: 'socklen_t' : illegal use of this type as an expression
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\ws2tcpip.h(418) : see declaration of 'socklen_t'
1>d:\ xxx\civetweb.c(14682): error C2146: syntax error : missing ';' before identifier 'len'
1>d:\ xxx\civetweb.c(14682): error C2065: 'len' : undeclared identifier
1>d:\ xxx\civetweb.c(14683): error C2143: syntax error : missing ';' before 'type'
1>d:\ xxx\civetweb.c(14692): error C2065: 'psa' : undeclared identifier
1>d:\ xxx\civetweb.c(14692): warning C4047: 'function' : 'sockaddr *' differs in levels of indirection from 'int'
1>d:\ xxx\civetweb.c(14692): warning C4024: 'getsockname' : different types for formal and actual parameter 2
1>d:\ xxx\civetweb.c(14692): error C2065: 'len' : undeclared identifier
1>d:\ xxx\civetweb.c(15233): error C2143: syntax error : missing ';' before 'type'
1>d:\ xxx\civetweb.c(15234): error C2143: syntax error : missing ';' before 'type'
1>d:\ xxx\civetweb.c(15235): error C2143: syntax error : missing ';' before 'type'
1>d:\ xxx\civetweb.c(15236): error C2143: syntax error : missing ';' before 'type'
1>d:\ xxx\civetweb.c(15239): error C2065: 'txt' : undeclared identifier
1>d:\ xxx\civetweb.c(15239): warning C4047: 'function' : 'char *' differs in levels of indirection from 'int'
1>d:\ xxx\civetweb.c(15239): warning C4024: 'mg_snprintf' : different types for formal and actual parameter 3
1>d:\ xxx\civetweb.c(15239): error C2065: 'txt' : undeclared identifier
1>d:\ xxx\civetweb.c(15240): error C2065: 'rctx' : undeclared identifier
1>d:\ xxx\civetweb.c(15240): error C2224: left of '.config' must have struct/union type
1>d:\ xxx\civetweb.c(15240): error C2065: 'txt' : undeclared identifier
1>d:\ xxx\civetweb.c(15245): error C2065: 'rctx' : undeclared identifier
1>d:\ xxx\civetweb.c(15245): error C2224: left of '.config' must have struct/union type
1>d:\ xxx\civetweb.c(15248): error C2065: 'rctx' : undeclared identifier
1>d:\ xxx\civetweb.c(15248): warning C4133: '=' : incompatible types - from 'int *' to 'mg_context *'
1>d:\ xxx\civetweb.c(15249): error C2065: 'ret' : undeclared identifier
1>d:\ xxx\civetweb.c(15249): error C2065: 'err' : undeclared identifier
1>d:\ xxx\civetweb.c(15250): error C2065: 'octx' : undeclared identifier
1>d:\ xxx\civetweb.c(15250): warning C4047: '=' : 'mg_context *' differs in levels of indirection from 'int'
1>d:\ xxx\civetweb.c(15261): error C2065: 'ret' : undeclared identifier

@Gitzzq
Copy link
Author

Gitzzq commented Aug 24, 2017

Never mind, I changed the extension name from .c to .cpp then all errors were gone.

@Gitzzq Gitzzq closed this as completed Aug 24, 2017
@bel2125
Copy link
Member

bel2125 commented Aug 24, 2017

Could you tell me what version you are using precisely (git commit number).
Your line numbers do not match with the current head version.

I think it's because the test environment switched from Visual Studio 2010 to 2013 when changing from 1.9 to 1.10, and Visual Studio 2010 uses C90 standard while the later uses C99

@Gitzzq
Copy link
Author

Gitzzq commented Aug 24, 2017

:), I mentioned in the initial post

upgrade the code from 1.8 to 1.10

@bel2125
Copy link
Member

bel2125 commented Aug 24, 2017

Never mind, I changed the extension name from .c to .cpp then all errors were gone.

Most likely the errors are some variables that are not declared on top of the function but somewhere in between. That's forbidden in C90 but allowed in C99 and in C++ as well.

@bel2125
Copy link
Member

bel2125 commented Aug 24, 2017

I meant, Visual Studio 2010 is no longer in the continuous integration test any more.
The current version is only tested with C99 compliant compilers.

@Gitzzq
Copy link
Author

Gitzzq commented Aug 24, 2017

Sorry I overlooked your question, I downloaded the latest version from Github yesterday.

1>d:\ xxx\civetweb.c(14682): error C2275: 'socklen_t' : illegal use of this type as an expression

the source code at line 14682 is:

socklen_t len = sizeof(conn->client.rsa.sin);

I downloaded the whole project as a zip file, I don't know the exact Git commit number.

@bel2125
Copy link
Member

bel2125 commented Aug 24, 2017

As expected, it's a declaration of a variable socklen_t len in the middle of the function.
Moving the declarations struct sockaddr *psa; socklen_t len; to the function header should solve this problem.

static struct mg_connection *
mg_connect_client_impl(const struct mg_client_options *client_options,
                       int use_ssl,
                       char *ebuf,
                       size_t ebuf_len)
{
	struct mg_connection *conn = NULL;
	SOCKET sock;
	union usa sa;
	struct sockaddr *psa;
	socklen_t len;
...

#ifdef USE_IPV6
	len = (sa.sa.sa_family == AF_INET) ? sizeof(conn->client.rsa.sin)
	                                   : sizeof(conn->client.rsa.sin6);
	psa = (sa.sa.sa_family == AF_INET)
	          ? (struct sockaddr *)&(conn->client.rsa.sin)
	          : (struct sockaddr *)&(conn->client.rsa.sin6);
#else
	len = sizeof(conn->client.rsa.sin);
	psa = (struct sockaddr *)&(conn->client.rsa.sin);
#endif
...

Later I can check it manually with Visual Studio 2010 on a different PC.

@bel2125
Copy link
Member

bel2125 commented Aug 25, 2017

I added a Visual Studio 2010 build to AppVeyor, but the current version of the check unit test framework does not support Visual Studio 2010 either (libcheck/check#125) - again, it would work in C++ mode (see StackOverflow). An older version of CivetWeb used an older Version of check that worked with VS2010.

I think it's not a big problem to re-enable the Visual Studio 2010 C mode build.
But anyway, this should not be tracked with this issue - let's keep this issue closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants