我試圖構建我的應用程序,其中包括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]
它看起來像有問題的功能是存在的。
我錯過了什麼?
這確實是一個問題。出於某種原因,OpenSSL「配置mingw [...]」不會添加類似'WINVER = XXX'的定義,而該定義在'ws2tcpip.h'中僅被定義爲'freeaddrinfo','getaddrinfo'和getnameinfo '如果'_WIN32_WINNT> = 0x0501'。因此,在運行'perl Configure mingw [...]'後,我在Makefile中爲CFLAGS添加了'-DWINVER = 0x0501 -D_WIN32_WINNT = 0x0501',以確保定義這些函數。用這個改變重建OpenSSL解決了這個問題。 –