2015-07-20 71 views
-1

我试图在Windows上的代码块中静态链接libcurl。libcurl静态链接 - 未定义引用到_imp__WSAIoctl @ 36'

我编译了带有“mingw32-make mingw32”的libcurl,并链接了结果库libcurl.a和libcurldll.a。我看到另一篇文章,提出解决方案是增加选项-lwldap32,但这没有什么区别:/

我在想什么?

编辑:下面是成功地完成了第一个编译命令的一个示例:

mingw32-g++.exe -Wall -pipe -mthreads -std=gnu++14 -D__GNUWIN32__ -D__WXMSW__ -DwxUSE_UNICODE -O2 -DCURL_STATICLIB -IE:\plus\libs\wxWidgets\include -IE:\plus\libs\curl-7.43.0\include -IE:\plus\libs\wxWidgets\lib\gcc_lib\mswu -c E:\plus\projects\hlr\hlrMain.cpp -o obj\Release\hlrMain.o 
E:\plus\projects\hlr\hlrMain.cpp:165:1: warning: 'virtual bool wxEvtHandler::TryValidator(wxEvent&)' is deprecated [-Wdeprecated-declarations] 
} 
^ 
In file included from E:\plus\libs\wxWidgets\include/wx/menu.h:14:0, 
       from E:\plus\projects\hlr\hlrMain.h:14, 
       from E:\plus\projects\hlr\hlrMain.cpp:10: 
E:\plus\libs\wxWidgets\include/wx/event.h:3683:22: note: declared here 
     virtual bool TryValidator(wxEvent& WXUNUSED(event)), return false;) 
        ^
E:\plus\libs\wxWidgets\include/wx/defs.h:615:43: note: in definition of macro 'wxDEPRECATED' 
#define wxDEPRECATED(x) wxDEPRECATED_DECL x 
             ^
E:\plus\libs\wxWidgets\include/wx/event.h:3682:5: note: in expansion of macro 'wxDEPRECATED_BUT_USED_INTERNALLY_INLINE' 
    wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
    ^
E:\plus\projects\hlr\hlrMain.cpp:165:1: warning: 'virtual bool wxEvtHandler::TryParent(wxEvent&)' is deprecated [-Wdeprecated-declarations] 
} 

链接到全功率输出,有很多的警告在这里:http://pastebin.com/a6s0mwQ7

失败编译:

mingw32-g++.exe -LE:\plus\libs\wxWidgets\lib\gcc_lib -o bin\Release\hlr.exe obj\Release\hlrApp.o obj\Release\hlrMain.o obj\Release\resource.res -s -lwldap32 -mthreads -lwxmsw30u -lwxpng -lwxjpeg -lwxtiff -lwxzlib E:\plus\libs\curl-7.43.0\lib\libcurl.a E:\plus\libs\curl-7.43.0\lib\libcurldll.a -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lcomctl32 -lwsock32 -lodbc32 -mwindows 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(connect.o):(.text+0xbda): undefined reference to `[email protected]' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x145): undefined reference to `_imp__ldap_err2string' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x187): undefined reference to `_imp__ldap_msgfree' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x1b4): undefined reference to `_imp__ldap_unbind_s' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x41f): undefined reference to `_imp__ldap_set_option' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x444): undefined reference to `_imp__ldap_init' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x47b): undefined reference to `_imp__ldap_simple_bind_s' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x4f1): undefined reference to `_imp__ldap_err2string' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x5a9): undefined reference to `_imp__ldap_search_s' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x5c2): undefined reference to `_imp__ldap_err2string' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x5f1): undefined reference to `_imp__ldap_first_entry' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x62c): undefined reference to `_imp__ldap_get_dn' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x6cc): undefined reference to `_imp__ldap_memfree' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x6e9): undefined reference to `_imp__ldap_first_attribute' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x71e): undefined reference to `_imp__ldap_get_values_len' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x911): undefined reference to `_imp__ldap_value_free_len' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x91e): undefined reference to `_imp__ldap_memfree' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x93b): undefined reference to `_imp__ber_free' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x983): undefined reference to `_imp__ldap_value_free_len' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x990): undefined reference to `_imp__ldap_memfree' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0x9ef): undefined reference to `_imp__ldap_next_attribute' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0xa14): undefined reference to `_imp__ber_free' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0xa29): undefined reference to `_imp__ldap_next_entry' 
E:\plus\libs\curl-7.43.0\lib\libcurl.a(ldap.o):(.text+0xa69): undefined reference to `_imp__ldap_memfree' 
+0

我没有看到你在编译步骤添加页眉路径。你只是缺少'-L/path/to/libcurl/headers/include'? – Honeybunch

+0

可能的重复[什么是未定义的引用/无法解析的外部符号错误,以及如何解决它?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external- symbol-error-and-how-do-i-fix) –

+0

它在第一个编译命令中,我将其视为已完成并成功完成:http://pastebin.com/a6s0mwQ7 – GemmaB89

回答

0

卷曲取决于OpenSSL。确保你已经链接了它。 _imp__WSAIoctl是“Ws2.lib”(Ws2_32.lib)的头文件“winsock2.h”的一部分。请确保在您的项目中解决了该引用。

+0

我已经根据刚刚添加的答案对问题进行了排序,但我回过头去尝试解决方案,因为我不太明白为什么我的修复程序具有它的效果,但我仍然遇到了同样的错误包括winsock2。 – GemmaB89

+0

任何想法为什么我的修复工作? – GemmaB89

0

对于任何有这个问题的人来说,事实证明我需要通过在代码块中添加一个链接器设置 - >链接库来使用完整的文件名libws2_32.a来添加ws2_32库。

如在网上其他地方建议的那样添加-lws2_32由于某种原因是不够的。

编译命令现在是:

mingw32-g++.exe -LE:\plus\libs\wxWidgets\lib\gcc_lib -o bin\Release\hlr.exe obj\Release\hlrApp.o obj\Release\hlrMain.o obj\Release\resource.res -s -mthreads -lwxmsw30u -lwxpng -lwxjpeg -lwxtiff -lwxzlib -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lcomctl32 -lwsock32 -lodbc32 E:\plus\libs\curl-7.43.0\lib\libcurl.a E:\plus\compilers\MinGW\i686-w64-mingw32\lib\libws2_32.a E:\plus\compilers\MinGW\i686-w64-mingw32\lib\libwldap32.a -mwindows 
+0

我敢打赌,这个问题实际上是''ws2_32'库需要在* libcurl库之后来到命令行。 GCC的链接器对库的排序很敏感(依赖于其他库的库通常需要在它们依赖的库之前进行排序)。 –

+0

并注意,如果是这种情况,那么答案*是*在“可能的重复”职位的“通用”答案*(副本有链接http://stackoverflow.com/a/24675715/1356926) 。即使这个通用答案很长,但值得阅读和理解,因为核心编译器工具的基本工作方式值得了解(或者至少知道)。 –

+0

我知道这个命令很重要,但我不完全理解需要什么命令,但是如果添加一个建议的lib不能解决问题,我总是尝试将命令复制出代码块并在命令提示符下运行有问题的库移动到最后,在这里没有任何区别。下次我遇到类似的事情时,我会阅读很长的回答。 – GemmaB89