-1

I'm trying to statically link libcurl in codeblocks on Windows.

I compiled libcurl with "mingw32-make mingw32", and have linked the resulting libraries libcurl.a and libcurldll.a. I saw another post on ere that suggested the solution was to add option -lwldap32, but that's made no difference :/

What am I missing?

EDIT: Here's a sample of the first compile command that completed successfully:

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]
 }

Link to full output with lots of warnings here: http://pastebin.com/a6s0mwQ7

Failed compile:

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 `_imp__WSAIoctl@36'
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'
GemmaB89
  • 165
  • 2
  • 16
  • I don't see where you add the header path in your compilation step. Are you just missing `-L/path/to/libcurl/headers/include`? – Honeybunch Jul 20 '15 at 19:01
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Captain Obvlious Jul 20 '15 at 19:10
  • It's in the first compile command, which i left out as completed succesfully: http://pastebin.com/a6s0mwQ7 – GemmaB89 Jul 20 '15 at 19:10
  • You need to shrink down everything and include it in your post, not a link to pastebin. – Captain Obvlious Jul 20 '15 at 19:12
  • I don't know what parts of the pastebin link i can get rid of, i didn't think any of it was important, but Honeybunch asked about it. For all I know one of the warnings could be the cause of my problems. I will edit in an example of it though. – GemmaB89 Jul 20 '15 at 19:17
  • I will read through the other thread you mention, it seems like a very generic answer, I have a much more specific problem – GemmaB89 Jul 20 '15 at 19:18
  • Found a solution, have added it to post, not sure why it works though if anyone would care to explain. – GemmaB89 Jul 20 '15 at 22:29

2 Answers2

1

For anyone else having this problem, turned out that I needed to add the ws2_32 lib by adding a linker settings->link library in code::blocks, using the full filename libws2_32.a.

Adding -lws2_32 as suggested elsewhere online wasn't enough for some reason.

Compile command now is:

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
GemmaB89
  • 165
  • 2
  • 16
  • I'll bet that the problem was really that the `ws2_32` library needed to come on the command line *after* the `libcurl` library. GCC's linker is sensitive to the ordering of libraries (libraries that depend on other libraries generally need to be ordered before the libraries they depend on). – Michael Burr Jul 21 '15 at 22:13
  • And note that if that is the case, then the answer *is* in the "generic" answer for the "possible duplicate" post (the duplicate has a link to http://stackoverflow.com/a/24675715/1356926). Even though that generic answer is long, it's worth reading and understanding because the basics of how core compiler tools work is worth knowing (or at least knowing about). – Michael Burr Jul 21 '15 at 22:32
  • I'm aware that the order matters, although I don't fully understand what order is required, but if adding a suggested lib does not fix the problem I always try copying the command out of codeblocks and running it in command prompt with the lib in question moved to the end, made no difference here. I will read the long answer next time i get stuck on something similar. – GemmaB89 Jul 21 '15 at 23:02
  • Another tip that might help in the future with linker problems when using gnu tools is to use the `-Wl,--verbose` option which tells the linker to dump information about what libraries are being searched and when they're being searched. – Michael Burr Jul 21 '15 at 23:30
0

Curl depends on OpenSSL. Make sure you have linked it. _imp__WSAIoctl is a part of "Ws2.lib"(Ws2_32.lib), header "winsock2.h". Try make sure that this reference is resolved in your project.

metizik
  • 1
  • 2
  • I'd already sorted the problem as per the answer I just added, I went back and tries your solution too though, as I don't really understand why my fix had the effect it did, but I still got the same errors when including winsock2. – GemmaB89 Jul 20 '15 at 22:28