5
votes

I have compiled libcurl using mingw32 and am trying to link it with my program using mingw32 for a Windows system from my Linux machine.

I was outputted the files, libcurl-4.dll libcurl.a libcurl.la libcurl.lai.

I have included them in my mingw32 libs folder at: /usr/x86_64-w64-mingw32/lib

I was able to find a few other topics on linking with the libstdc++ and libgcc to take care dependency errors while executed but when trying to add libcurl.a it will not compile period.

I used the following:

$ x86_64-w64-mingw32-g++ main.cpp -o hello.exe -static-libgcc -static-libstdc++ -static "/usr/x86_64-w64-mingw32/lib/libcurl.a" -lpthread

However, I cannot not get it to use the libcurl.a and am continuing to receive these errors.

/tmp/ccIceRus.o:main.cpp:(.text+0xde): undefined reference to `__imp_curl_easy_init'
/tmp/ccIceRus.o:main.cpp:(.text+0x106): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x122): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x13e): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x159): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x169): undefined reference to `__imp_curl_easy_perform'
/tmp/ccIceRus.o:main.cpp:(.text+0x180): undefined reference to `__imp_curl_easy_strerror'
/tmp/ccIceRus.o:main.cpp:(.text+0x197): undefined reference to `__imp_curl_easy_cleanup'
/usr/bin/x86_64-w64-mingw32-ld: /tmp/ccIceRus.o: bad reloc address 0x80 in section `.xdata'
collect2: error: ld returned 1 exit status

What am I doing wrong?. I can not get past this. I know it has to be some stupid issue.

Thank you.

1
No need to mention static word since you're using a full path to an object files archive — which isn't dynamic library anyway. Try this way: $ x86_64-w64-mingw32-g++ main.cpp "/usr/x86_64-w64-mingw32/lib/libcurl.a" -o hello.exe -static-libgcc -static-libstdc++ -lpthreadHi-Angel
This will work if shared libraries are enabled, however, not so much luck if they are solely using a static 'archive' library.woahguy

1 Answers

5
votes

I was able to solve the question by specifying -DCURL_STATICLIB, as well as linking some other dependencies.

x86_64-w64-mingw32-g++ main.cpp -o hello.exe -DCURL_STATICLIB -static -lstdc++ -lgcc -lpthread -lcurl -lwldap32 -lws2_32