user3696412
user3696412

Reputation: 1419

Static Library linked but still undefined references

I am trying to link libcurl statically to my programm (just libcurl, not all of its dependencies). I build libcurl myself to get down the dependencies to a minimum that should be present on most linux systems anyway.

I try to compile with

g++ foo.cpp -I/tmp/curl/include/curl/ -L/tmp/curl/lib/libcurl.a

but still get

curl_downloads.cpp:(.text+0xe): undefined reference to `curl_global_init'
/tmp/ccY0XMUo.o: In function `curlDownloadToFile(void*, std::string const&, std::string const&, std::string const&, std::string)': 
curl_downloads.cpp:(.text+0x36): undefined reference to `curl_easy_init'
curl_downloads.cpp:(.text+0xcb): undefined reference to `curl_easy_escape'
curl_downloads.cpp:(.text+0x119): undefined reference to `curl_easy_setopt'
curl_downloads.cpp:(.text+0x15d): undefined reference to `curl_easy_setopt'
curl_downloads.cpp:(.text+0x178): undefined reference to `curl_easy_setopt'
curl_downloads.cpp:(.text+0x192): undefined reference to `curl_easy_setopt'
...

but nm libcurl.a shows

nm libcurl.a | grep easy
                 U curl_easy_unescape
0000000000000000 T curl_easy_escape
00000000000002f0 T curl_easy_unescape
libcurl_la-easy.o:
0000000000000590 T curl_easy_cleanup  
0000000000000630 T curl_easy_duphandle
00000000000005f0 T curl_easy_getinfo
0000000000000270 T curl_easy_init
00000000000008e0 T curl_easy_pause
0000000000000350 T curl_easy_perform
0000000000000a60 T curl_easy_recv
0000000000000800 T curl_easy_reset
0000000000000ad0 T curl_easy_send
00000000000002b0 T curl_easy_setopt
0000000000000080 t easy_connection
0000000000001580 T Curl_multi_set_easy_connection
             U curl_easy_init
0000000000000000 T curl_easy_strerror

so the functions should be present. I also tried like every possible order of the arguments in the g++ call, I always get the missing references.

So what am I missing here?

Upvotes: 1

Views: 1589

Answers (1)

jww
jww

Reputation: 102444

g++ foo.cpp -I/tmp/curl/include/curl/ -L/tmp/curl/lib/libcurl.a

An archive (*.a) file is simply a collection of object files (*.o). So you specify an archive just like you would object files.

In your case, drop the -L (-L is a path, and not a library include switch), and specify the archive's fully qualified path:

g++ foo.cpp -I/tmp/curl/include/curl/ -o foo.exe /tmp/curl/lib/libcurl.a

Upvotes: 2

Related Questions