2017-05-26 44 views
1

我试图构建我的应用程序,其中包括libcurl + openssl + zlib(全部从源代码构建而成)。它给了我下面的链接错误:Mingw未定义的引用libws2_32('getnameinfo','getaddrinfo',...)

g++ -std=c++0x -DWINVER=0x0501 -DCURL_STATICLIB "-ID:\\PROJEKTY\\PC\\libcurl_openssl_zlib\\src\\lib" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\main.o" "..\\src\\main.cpp" 
g++ "-LD:\\PROJEKTY\\PC\\libcurl_openssl_zlib\\src\\lib\\curl" "-LD:\\PROJEKTY\\PC\\libcurl_openssl_zlib\\src\\lib\\openssl" "-LD:\\PROJEKTY\\PC\\libcurl_openssl_zlib\\src\\lib\\zlib" -v -static-libgcc -static-libstdc++ -o libcurl_openssl_zlib.exe "src\\main.o" -lcurl -lcurldll -lssl -lcrypto -lz -lwldap32 -lws2_32 
Using built-in specs. 
COLLECT_GCC=g++ 
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/5.3.0/lto-wrapper.exe 
Target: mingw32 
Configured with: ../src/gcc-5.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --prefix=/mingw --disable-win32-registry --target=mingw32 --with-arch=i586 --enable-languages=c,c++,objc,obj-c++,fortran,ada --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libintl-prefix=/mingw --enable-libstdcxx-debug --with-tune=generic --enable-libgomp --disable-libvtv --enable-nls : (reconfigured) ../src/gcc-5.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --prefix=/mingw --disable-win32-registry --target=mingw32 --with-arch=i586 --enable-languages=c,c++,objc,obj-c++,fortran,ada --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-debug --with-tune=generic --enable-libgomp --disable-libvtv --enable-nls 
Thread model: win32 
gcc version 5.3.0 (GCC) 
COMPILER_PATH=c:/mingw/bin/../libexec/gcc/mingw32/5.3.0/;c:/mingw/bin/../libexec/gcc/;c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ 
LIBRARY_PATH=c:/mingw/bin/../lib/gcc/mingw32/5.3.0/;c:/mingw/bin/../lib/gcc/;c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/lib/;c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../ 
COLLECT_GCC_OPTIONS='-LD:\PROJEKTY\PC\libcurl_openssl_zlib\src\lib\curl' '-LD:\PROJEKTY\PC\libcurl_openssl_zlib\src\lib\openssl' '-LD:\PROJEKTY\PC\libcurl_openssl_zlib\src\lib\zlib' '-v' '-static-libgcc' '-o' 'libcurl_openssl_zlib.exe' '-mtune=generic' '-march=i586' 
c:/mingw/bin/../libexec/gcc/mingw32/5.3.0/collect2.exe -plugin c:/mingw/bin/../libexec/gcc/mingw32/5.3.0/liblto_plugin-0.dll -plugin-opt=c:/mingw/bin/../libexec/gcc/mingw32/5.3.0/lto-wrapper.exe -plugin-opt=-fresolution=C:\Users\Jacek\AppData\Local\Temp\cchJKgec.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -Bdynamic -o libcurl_openssl_zlib.exe c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../crt2.o c:/mingw/bin/../lib/gcc/mingw32/5.3.0/crtbegin.o -LD:\PROJEKTY\PC\libcurl_openssl_zlib\src\lib\curl -LD:\PROJEKTY\PC\libcurl_openssl_zlib\src\lib\openssl -LD:\PROJEKTY\PC\libcurl_openssl_zlib\src\lib\zlib -Lc:/mingw/bin/../lib/gcc/mingw32/5.3.0 -Lc:/mingw/bin/../lib/gcc -Lc:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/lib -Lc:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../.. src\main.o -lcurl -lcurldll -lssl -lcrypto -lz -lwldap32 -lws2_32 -Bstatic -lstdc++ -Bdynamic -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt c:/mingw/bin/../lib/gcc/mingw32/5.3.0/crtend.o 
D:\PROJEKTY\PC\libcurl_openssl_zlib\src\lib\openssl/libcrypto.a(b_addr.o):b_addr.c:(.text+0xaa): undefined reference to `getnameinfo' 
D:\PROJEKTY\PC\libcurl_openssl_zlib\src\lib\openssl/libcrypto.a(b_addr.o):b_addr.c:(.text+0xb48): undefined reference to `getaddrinfo' 
D:\PROJEKTY\PC\libcurl_openssl_zlib\src\lib\openssl/libcrypto.a(b_addr.o):b_addr.c:(.text+0xca0): undefined reference to `getaddrinfo' 
D:\PROJEKTY\PC\libcurl_openssl_zlib\src\lib\openssl/libcrypto.a(b_addr.o):b_addr.c:(.text+0x819): undefined reference to `freeaddrinfo' 
D:\PROJEKTY\PC\libcurl_openssl_zlib\src\lib\openssl/libcrypto.a(init.o):init.c:(.text+0x212): undefined reference to `GetModuleHandleEx' 
D:\PROJEKTY\PC\libcurl_openssl_zlib\src\lib\openssl/libcrypto.a(init.o):init.c:(.text+0x984): undefined reference to `GetModuleHandleEx' 
collect2.exe: error: ld returned 1 exit status 

从上面可以看出,-lws2_32-lcrypto后说,这意味着它不应该与链接顺序的问题。 “以防万一”,我也做了-DWINVER=0x0501建议在simiar线程没有任何结果,即使我不明白这会影响错误潜伏在链接无论如何(相反,它会抛出一个错误或关于隐式声明的警告期间汇编)。

我向链接器投掷了详细的标志以查看库搜索路径,它们是正确的。去一个libws2_32.a位于并运行它nm返回如下:

MSYS /c/MinGW/lib 
$ nm.exe -g libws2_32.a | grep getnameinfo 
00000000 I [email protected] 
00000000 T [email protected] 

它看起来像有问题的功能是存在的。

我错过了什么?

回答

2

你的libws2_32.a不是一个真正的静态库,而是一个导入库。这只是在运行时动态链接到dll所需的窗口上的一个存根。

要使用它,您必须绑定前缀为__imp__(而不是_)的符号。这是__declspec(dllimport)为你做的。因此,在编译你的openssl时(它现在需要与一个正常的静态库链接),ws2_32原型在编译时就失败了。

+0

这确实是一个问题。出于某种原因,OpenSSL“配置mingw [...]”不会添加类似'WINVER = XXX'的定义,而该定义在'ws2tcpip.h'中仅被定义为'freeaddrinfo','getaddrinfo'和getnameinfo '如果'_WIN32_WINNT> = 0x0501'。因此,在运行'perl Configure mingw [...]'后,我在Makefile中为CFLAGS添加了'-DWINVER = 0x0501 -D_WIN32_WINNT = 0x0501',以确保定义这些函数。用这个改变重建OpenSSL解决了这个问题。 –

相关问题