Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to compile Libcurl for my project but I am getting below error.


g++ -g -o Main.exe Main.o L"C:\Test\src\WebSocket\lib" -D_WIN32_WINNT=0x0601 -DWINVER=0x0601 -DCURL_STATICLIB -llibcurl

/mingw32/bin/ld.exe: cannot find -llibcurl


When I built libcurl usinf mingw32 I got two files i.e. libcurl.a, libcurl.la.
I added both files under <c:\test\src\websocket\lib>.
I am not sure why linker is unable to link these libraries.

Can anybody with good compiler and libcurl understanding help for this?

What I have tried:

Initially I was getting error like :
main.cpp:11: undefined reference to __imp__curl_easy_init'
main.cpp:13: undefined reference to __imp__curl_easy_setopt'
main.cpp:14: undefined reference to __imp__curl_easy_perform'
main.cpp:17: undefined reference to __imp__curl_easy_cleanup'

Then I realized I need to link my libcurl library which I did as below:

WS_DIR = "C:\Test\src\WebSocket\curl"
WS_LIB = "C:\Test\src\WebSocket\lib"

g++ -c -std=c++11 -g -fpermissive src/Main.cpp -I${WS_DIR} -D_WIN32_WINNT=0x0601 -DWINVER=0x0601 -L${WS_LIB} -DCURL_STATICLIB -llibcurl

I have compiled cURL using mingw32.

But now i am facing linking issue.
please help.
Posted
Updated 15-Mar-16 0:25am

1 solution

If you look closely at the Link Options - Using the GNU Compiler Collection (GCC)[^], you would see that the option should be -lcurl.
 
Share this answer
 
Comments
Member 10305620 15-Mar-16 6:44am    
@Richard: Yeah I found out how silly the mistake was. Gosh !! I hate these stupid mistakes I make.

But now I am facing old issue again with all sort of "undefined reference".
It's so annoying to get a lib compiled with project in c++.
Below are the errors, Please help or put in me right direction as it's pretty urgent for me :(

\src\WebSocket\lib\libcurl.a(libcurl_la-connect.o):(.text+0x158): undefined reference to `__errno'
\src\WebSocket\lib\libcurl.a(libcurl_la-connect.o):(.text+0x30a): undefined reference to `getpeername'
\src\WebSocket\lib\libcurl.a(libcurl_la-connect.o):(.text+0x313): undefined reference to `__errno'
\src\WebSocket\lib\libcurl.a(libcurl_la-connect.o):(.text+0x377): undefined reference to `__errno'
\src\WebSocket\lib\libcurl.a(libcurl_la-connect.o):(.text+0x3f0): undefined reference to `__errno'
\src\WebSocket\lib\libcurl.a(libcurl_la-connect.o):(.text+0x419): undefined reference to `__errno'
\src\WebSocket\lib\libcurl.a(libcurl_la-connect.o):(.text+0x515): undefined reference to `recv'
\src\WebSocket\lib\libcurl.a(libcurl_la-connect.o):(.text+0x6ba): undefined reference to `socket'
\src\WebSocket\lib\libcurl.a(libcurl_la-connect.o):(.text+0x861): undefined reference to `__errno'
\src\WebSocket\lib\libcurl.a(libcurl_la-connect.o):(.text+0xbbb): undefined reference to `__errno'
\src\WebSocket\lib\libcurl.a(libcurl_la-connect.o):(.text+0xd8b): undefined reference to `__errno'
\src\WebSocket\lib\libcurl.a(libcurl_la-connect.o):(.text+0xdfb): undefined reference to `__errno'
\src\WebSocket\lib\libcurl.a(libcurl_la-connect.o):(.text+0xf0d): undefined reference to `__errno'
\src\WebSocket\lib\libcurl.a(libcurl_la-connect.o):(.text+0x137d): more undefined references to `__errno' follow
\src\WebSocket\lib\libcurl.a(libcurl_la-select.o):(.text+0x7a): undefined reference to `poll'
\src\WebSocket\lib\libcurl.a(libcurl_la-select.o):(.text+0xa3): undefined reference to `__errno'
\src\WebSocket\lib\libcurl.a(libcurl_la-select.o):(.text+0x18d): undefined reference to `poll'
\src\WebSocket\lib\libcurl.a(libcurl_la-select.o):(.text+0x197): undefined reference to `__errno'
\src\WebSocket\lib\libcurl.a(libcurl_la-select.o):(.text+0x205): undefined reference to `poll'
\src\WebSocket\lib\libcurl.a(libcurl_la-select.o):(.text+0x31d): undefined reference to `poll'
\src\WebSocket\lib\libcurl.a(libcurl_la-select.o):(.text+0x329): undefined reference to `__errno'
\src\WebSocket\lib\libcurl.a(libcurl_la-nonblock.o):(.text+0x1d): undefined reference to `fcntl'
\src\WebSocket\lib\libcurl.a(libcurl_la-nonblock.o):(.text+0x3e): undefined reference to `fcntl'
\src\WebSocket\lib\libcurl.a(libcurl_la-nonblock.o):(.text+0x5e): undefined reference to `fcntl'
\src\WebSocket\lib\libcurl.a(libcurl_la-hostip.o):(.text+0xf1): undefined reference to `_imp___ctype_'
\src\WebSocket\lib\libcurl.a(libcurl_la-hostip.o):(.text+0x64b): undefined reference to `sigprocmask'
\src\WebSocket\lib\libcurl.a(libcurl_la-hostip.o):(.text+0x6e5): undefined reference to `sigaction'
\src\WebSocket\lib\libcurl.a(libcurl_la-hostip.o):(.text+0x722): undefined reference to `sigaction'
\src\WebSocket\lib\libcurl.a(libcurl_la-hostip.o):(.text+0x748): undefined reference to `alarm'
\src\WebSocket\lib\libcurl.a(libcurl_la-hostip.o):(.text+0x765): undefined reference to `sigprocmask'
\src\WebSocket\lib\libcurl.a(libcurl_la-hostip.o):(.text+0x771): undefined reference to `setjmp'
\src\WebSocket\lib\libcurl.a(libcurl_la-hostip.o):(.text+0x851): undefined reference to `alarm'
\src\WebSocket\lib\libcurl.a(libcurl_la-hostip.o):(.text+0x875): undefined reference to `sigaction'
\src\WebSocket\lib\libcurl.a(libcurl_la-hostip.o):(.text+0x888): undefined reference to `alarm'
\src\WebSocket\lib\libcurl.a(libcurl_la-hostip.o):(.text+0x8be): undefined reference to `alarm'
\src\WebSocket\lib\libcurl.a(libcurl_la-cookie.o):(.text+0x3fe): undefined reference to `strtok_r'
\src\WebSocket\lib\libcurl.a(libcurl_la-cookie.o):(.text+0x47c): undefined reference to `strtok_r'
\src\WebSocket\lib\
Richard MacCutchan 15-Mar-16 6:47am    
You are missing some other libraries, at a guess some of the standard ones. Google the name of the missing items in the messages above and that should lead you to the names of the required libraries.
Member 10305620 15-Mar-16 6:56am    
@Richard: I have spent whole day figuring out and looking through google but couldn't find any useful information :(
Richard MacCutchan 15-Mar-16 7:47am    
Hmm, you're right, the Linux man pages do not seem to identify the library required for each system call, which is rather useless. At the very least you need that standard c library (-lc). As for the others I would try one of the Linux support forums.

As an aside, I do wonder why you are using gnu to create a Windows program.
Member 10305620 15-Mar-16 23:44pm    
Exactly. My requirement is to write a WebClient for a server.
But c++ doesn't have inbuilt support as such and while going through many posts I found this library.
But I am just following the step mentioned in the library documentation for compiling it along side my application.
Could suggest any simple plug and play kind of library which I can directly use without any dependency, you know like some header type library.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900