我尝试使用poco库创建简单的HTTPS服务器。我有SSL层问题,因为我无法正确初始化它。 这是我的代码:
#ifdef SSL
// initialize SSL
Poco::Net::initializeSSL();
Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> pCert =
new Poco::Net::ConsoleCertificateHandler(false);
Poco::Net::Context::Ptr pContext =
new Poco::Net::Context(
Poco::Net::Context::SERVER_USE,
"",
"server.pem",
"",
Poco::Net::Context::VERIFY_NONE,
9,
false,
"ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
Poco::Net::SSLManager::instance().initializeClient(0, pCert, pContext);
#endif //SSL
if (port == UNKNOWN_PORT)
return 1;
// set-up a server socket
#ifdef SSL
SecureServerSocket svs(port, 64, pContext);
#else
ServerSocket svs(port);
#endif //SSL
// set-up a HTTPServer instance
Poco::Net::HTTPServer srv(new RequestHandlerFactory, svs, new HTTPServerParams);
当我尝试使用MSVC2015构建它时会产生很多错误(见下文)。与poco-library一起提供的构建示例不会给出任何错误。
仅使用SecureServerSocket
和initializeSSL
,其余部分不会出现未处理的异常。
为什么我收到未定义符号的编译错误,我该如何解决?
1>------ Build started: Project: PocoNetServer, Configuration: Release Win32 ------
1> HTTPServer.cpp
1>D:\Programming\OpenSSL-Win32\include\openssl/ossl_typ.h(178): warning C4091: 'typedef ': ignored on left of 'ssl_st' when no variable is declared
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(390): error C2065: 's': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(391): error C2059: syntax error: 'const'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(393): error C2065: 's': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(393): error C2062: type 'void' unexpected
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(402): error C2065: 's': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(402): error C2062: type 'unsigned int' unexpected
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(406): error C2065: 's': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(406): error C2062: type 'unsigned int' unexpected
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(409): error C2065: 's': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(409): error C2062: type 'unsigned int' unexpected
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(440): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(441): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(442): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(443): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(444): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(445): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(446): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(447): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(448): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(449): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(450): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(451): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(453): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(455): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(456): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(457): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(461): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(468): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(837): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(838): error C2065: 'ssl': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(839): error C2065: 'cb': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(839): error C2062: type 'int' unexpected
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(853): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(855): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(857): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(869): error C2065: 's': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(871): error C2065: 'ctx': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(873): error C2065: 's': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(873): error C2062: type 'int' unexpected
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(874): error C2065: 's': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(874): error C2062: type 'unsigned char' unexpected
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(875): error C2065: 's': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(876): error C2065: 's': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(876): error C2062: type 'unsigned char' unexpected
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(905): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(999): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1002): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1006): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1021): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1040): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1076): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1083): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1090): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1094): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1101): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1106): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1131): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1138): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1162): error C2059: syntax error: '*'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1247): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1249): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1252): error C2143: syntax error: missing ')' before '('
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1252): error C2065: 'ssl': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1252): error C2065: 'x509': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1252): error C2275: 'X509': illegal use of this type as an expression
1> D:\Programming\OpenSSL-Win32\include\openssl/ossl_typ.h(154): note: see declaration of 'X509'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1253): error C2065: 'pkey': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1253): error C2275: 'EVP_PKEY': illegal use of this type as an expression
1> D:\Programming\OpenSSL-Win32\include\openssl/ossl_typ.h(133): note: see declaration of 'EVP_PKEY'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1253): error C2206: 'SSL_CTX_set_client_cert_cb': typedef cannot be used for function definition
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1253): error C2059: syntax error: ')'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1254): error C2065: 'ssl': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1254): error C2065: 'x509': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1254): error C2275: 'X509': illegal use of this type as an expression
1> D:\Programming\OpenSSL-Win32\include\openssl/ossl_typ.h(154): note: see declaration of 'X509'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1255): error C2065: 'pkey': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1255): error C2275: 'EVP_PKEY': illegal use of this type as an expression
1> D:\Programming\OpenSSL-Win32\include\openssl/ossl_typ.h(133): note: see declaration of 'EVP_PKEY'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1255): error C2206: 'SSL_CTX_get_client_cert_cb': typedef cannot be used for function definition
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1260): error C2143: syntax error: missing ')' before '('
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1260): error C2065: 'ssl': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1262): error C2062: type 'unsigned char' unexpected
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1264): error C2059: syntax error: ')'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1266): error C2143: syntax error: missing ')' before '('
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1266): error C2065: 'ssl': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1268): error C2062: type 'unsigned char' unexpected
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1270): error C2059: syntax error: ')'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1273): error C2143: syntax error: missing ')' before '('
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1273): error C2065: 'ssl': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1274): error C2059: syntax error: 'const'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1277): error C2059: syntax error: ')'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1279): error C2143: syntax error: missing ')' before '('
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1279): error C2065: 'ssl': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1280): error C2062: type 'unsigned char' unexpected
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1284): error C2059: syntax error: ')'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1285): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1302): error C2065: 'ssl': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1302): error C2059: syntax error: 'const'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1305): error C2143: syntax error: missing ')' before '('
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1305): error C2065: 'ssl': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1306): error C2059: syntax error: 'const'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1310): error C2059: syntax error: ')'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1311): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1322): error C2143: syntax error: missing ')' before '('
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1323): error C2065: 'ssl': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1324): error C2059: syntax error: 'const'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1337): error C2059: syntax error: ')'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1338): error C2065: 'ssl': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1339): error C2065: 'psk_client_callback': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1340): error C2065: 'ssl': undeclared identifier
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1341): error C2059: syntax error: 'const'
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1356): error C2143: syntax error: missing ')' before '('
1>D:\Programming\OpenSSL-Win32\include\openssl/ssl.h(1357): fatal error C1003: error count exceeds 100; stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
答案 0 :(得分:3)
从您的代码中,您看起来有一个名为SSL
的宏。这恰好是OpenSSL定义的类型,从ossl_typ.h
中的第178行开始:
typedef struct ssl_st SSL;
我建议使用不同的宏名称。