0

I am using MSYS2, and MinGW-w64 originated libraries and toolchains (from pacman repository 'mingw32') via mingw32_shell.bat environment.

I use mingw32/mingw-w64-i686-gcc package; mingw32 packaged are path prefixed /mingw32, so the gcc binary is /mingw32/gcc, for example.

What I am in trouble with is, linking cURL libraries with g++. I installed mingw32/mingw-w64-i686-curl. It provides /mingw32/include/curl/curl.h, /mingw32/lib/libcurl.a, /mingw32/lib/libcurl.dll.a, and so on. While this package does not provide curl.pc, -lcurl does not work. So I run:

$ curl-config --cflags
-I/mingw32/include
$ curl-config --libs
-L/mingw32/lib -lcurl -lidn -lrtmp -lssh2 -lssl -lcrypto -lgdi32 -lssl -lcrypto -lwldap32 -lz -lws2_32
$ curl-config --static-libs
/mingw32/lib/libcurl.a -LC:/msys64/mingw32/lib -pipe -LC:/msys64/mingw32/lib -lidn -lrtmp -lssh2 -lssl -lcrypto -lgdi32 -lssl -lcrypto -lwldap32 -lz -lws2_32

Good. I added -I/mingw32/include to CXXFLAGS in my Makefile, and added /mingw32/lib/libcurl.dll.a to g++ arguments in the executable linking target in the Makefile. (The CXXFLAGS contains -std=c++11 -fopenmp -O2 -g -I..)

It failed.

main.o: In function `query':
C:\Users\Administrator\ngd\5/main.cc:80: undefined reference to `_imp__curl_easy_init'
main.o: In function `urlencode':
C:\Users\Administrator\ngd\5/main.cc:34: undefined reference to `_imp__curl_free'
C:\Users\Administrator\ngd\5/main.cc:29: undefined reference to `_imp__curl_easy_escape'
C:\Users\Administrator\ngd\5/main.cc:30: undefined reference to `_imp__curl_easy_escape'
main.o: In function `query':
C:\Users\Administrator\ngd\5/main.cc:88: undefined reference to `_imp__curl_easy_setopt'
C:\Users\Administrator\ngd\5/main.cc:93: undefined reference to `_imp__curl_easy_perform'
C:\Users\Administrator\ngd\5/main.cc:94: undefined reference to `_imp__curl_easy_cleanup'
collect2.exe: error: ld returned 1 exit status

(main.o is from main.cc, which includes curl/curl.h and curl function usages.)

I added -DCURL_STATICLIBS -I/mingw32/include to CXXFLAGS instead, and /mingw32/lib/libcurl.a to g++ arguments for an executable.

Failed again.

main.o: In function `query':
C:\Users\Administrator\ngd\5/main.cc:80: undefined reference to `curl_easy_init'
main.o: In function `urlencode':
C:\Users\Administrator\ngd\5/main.cc:34: undefined reference to `curl_free'
C:\Users\Administrator\ngd\5/main.cc:35: undefined reference to `curl_free'
C:\Users\Administrator\ngd\5/main.cc:29: undefined reference to `curl_easy_escape'
C:\Users\Administrator\ngd\5/main.cc:30: undefined reference to `curl_easy_escape'
main.o: In function `query':
C:\Users\Administrator\ngd\5/main.cc:88: undefined reference to `curl_easy_setopt'
C:\Users\Administrator\ngd\5/main.cc:90: undefined reference to `curl_easy_setopt'
C:\Users\Administrator\ngd\5/main.cc:91: undefined reference to `curl_easy_setopt'
C:\Users\Administrator\ngd\5/main.cc:93: undefined reference to `curl_easy_perform'
C:\Users\Administrator\ngd\5/main.cc:94: undefined reference to `curl_easy_cleanup'
collect2.exe: error: ld returned 1 exit status

What I did to examine:

$ nm /mingw32/lib/libcurl.a
... (other files)
libcurl_la-escape.o:
...
00000340 T _curl_free
...
(end of libcurl_la-escape.o)
... (other files)

$ nm /mingw32/lib/libcurl.dll.a
... (other files)
d000018.o:
...
00000000 I __imp__curl_free
00000000 T _curl_free
...
(end of d000018.o)
... (other files)

So the problem is (I think) __imp__curl_free or _curl_free is defined, while the compiler requires _imp__curl_free or curl_free.

Any solution for this please?

eonj
  • 109
  • 1
  • 1
  • 12
  • I also had the same/similar Problem. I was using the wrong architecture of the library. Can you check that? – Thomas Sparber Jun 15 '15 at 08:33
  • @ThomasSparber, when I unpack `libcurl.a` and run `$ file libcurl_la-escape.o`, it results `libcurl_la-escape.o: MS Windows COFF Intel 80386 object file`. Isn't it the right architecture? – eonj Jun 15 '15 at 08:37
  • Yes this sounds correct. Anyways I'm suspecting there is anything wrong with the Version you are using. Do you have the possibility to install a different one? Or download it manually. – Thomas Sparber Jun 15 '15 at 08:44
  • I `make install`ed curl, and the result `libcurl.a` contains underscored identifiers. Still link error. confusing. – eonj Jun 15 '15 at 09:31

0 Answers0