1

I downloaded the libcurl curl-7.34.0-devel-mingw32.zip from http://curl.haxx.se/gknw.net/7.34.0/dist-w32/curl-7.34.0-devel-mingw32.zip.

I use Eclipse Kepler with MinGW as the toolchain (GCC compiler). I created html.cpp and then test the code from the example http://curl.haxx.se/libcurl/c/simple.html:

I included the headers:

#include<iostream>
#include<curl/curl.h>
using namespace std;

There are 5 cURL functions. Only 2 of them (curl_easy_init,curl_easy_setopt)are said to be 'undefined reference'. The compiler message:

Info: Internal Builder is used for build
g++ -O3 -Wall -c -fmessage-length=0 -o html.o "..\\html.cpp" 
g++ -static-libgcc -static-libstdc++ -o HTML.exe html.o 
html.o:html.cpp:(.text.startup+0x12): undefined reference to `_imp__curl_easy_init'
html.o:html.cpp:(.text.startup+0x1e): undefined reference to `_imp__curl_easy_setopt'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: html.o: bad reloc         address 0x1e in section `.text.startup'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link     failed: Invalid operation
collect2.exe: error: ld returned 1 exit status

The other 3 functions said to be fine:

curl_easy_perform
curl_easy_strerror
curl_easy_cleanup

I have tried to set to properties to tell the MinGW linker to include the headers and library files. The same situation as the above or the compiler simply says the .a files not found. Adding -lcurl or -DCURL_STATICLIB to the linker's flag is useless as well.

I have also tried to copy the libraries(.a files) and the headers(.h files) of libcurl to the folders bin, include and lib inside C:\MinGW and C:\gcc-4.8.1. It turns out to be no change.

Sadly, the first challenge of using cURL is not coding but the compilation. How can I solve this problem? Thanks you guys!

Fire
  • 11
  • 1
  • 1
    Your compilation command `g++ ...` does not show that you are linking with curl. You need something like `-lcurl` or `/usr/local/lib/libcurl.a` in your parameters to link and thus solve the "undefined references" errors – Brandin Jan 15 '14 at 07:43
  • `-lcurl` doesn't help. When I give the correct directory of the libraries(libcurl.a libcurldll.a), the compiler says not found – Fire Jan 16 '14 at 13:12
  • I doubt that the .dll files(the files inside the folder bin) isn't linked. Is that true? – Fire Jan 16 '14 at 13:17
  • If `-lcurl` doesn't work you can also give a full path to the library. i.e. `/foo/lib/libcurl.a` You must give a full filename, not a directory – Brandin Jan 16 '14 at 14:13
  • i included the libcurl.a with the correct path but still doesn't work – Fire Jan 16 '14 at 15:14
  • Why doesn't it work? If it says not found then maybe the path is wrong. If it says something else then you might have another clue at that point. – Brandin Jan 16 '14 at 16:50
  • I have no idea. The compiler returns: g++ "-LC:\\curl-7.34.0-devel-mingw32\\lib" -static-libgcc -static-libstdc++ -o HTML.exe html.o "-lC:\\curl-7.34.0-devel-mingw32\\lib\\libcurldll.a" "-lC:\\curl-7.34.0-devel-mingw32\\lib\\libcurl.a" c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lC:\curl-7.34.0-devel-mingw32\lib\libcurldll.a c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lC:\curl-7.34.0-devel-mingw32\lib\libcurl.a collect2.exe: error: ld returned 1 exit status No idea about this clue. – Fire Jan 17 '14 at 14:45
  • For MinGW instead of 'C:\foo\bar\baz.a' or 'C:\\foo\\bar\\baz.a' its better to use the format '/c/foo/bar/baz.a'. Try at the MinGW prompt first `ls -l /c/foo/bar/baz.a` and make sure your library path is correct – Brandin Jan 17 '14 at 19:55

1 Answers1

0
  1. ensure that curl folder is located in project directory with your main.cpp code
  2. in terminal run "g++ -I./curl/include -L./curl/lib -o html html.cpp -lcurl"

If it doesn't work try creating windows environmental paths to /bin location in same directory.

If that works then you can move the folder out whereever and remember to change the links to the correct filepath.

My long answer here explains indepth the workings of curl - I can't seem to link g++ to my installed libcurl