I'm writing a program which uses curl to be run on Linux PCs which will be used by a number of different users. I cannot make the users all install curl on their individual machines, so I have tried to link curl in statically, rather than using libcurl.so. I downloaded the source and created a libcurl.a static library. However, when I tried to link it in with my program, it showed a lot of disparate undefined references, in other words it had dependencies on other libraries. It would be hard to figure out all the things it's calling for and link in static versions of those libraries too. How do people use curl for programs that are to be distributed to users, most of whom don't have curl libraries on their PCs? How can I use curl in my program completely statically.
Thanks in advance for any enlightenment you can shed.
I did use -ldl. I presume that it links in libdl.a. But after that it still complained about numerous undefined references. A small fraction is:
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../libcurl.a(strerror.o): In function `Curl_idn_strerror':
strerror.c: (.text+0x6e): undefined reference to `idna_strerror'
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../libcurl.a(timeval.o): In function `curlx_tvnow':
timeval.c: (.text+0x89): undefined reference to `clock_gettime'
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../libcurl.a(url.o): In function `fix_hostname':
url.c: (.text+0x10ee): undefined reference to `stringprep_check_version'
url.c: (.text+0x1113): undefined reference to `idna_to_ascii_lz'
url.c: (.text+0x111b): undefined reference to `stringprep_locale_charset'
url.c: (.text+0x1157): undefined reference to `idna_to_unicode_lzlz'
url.c: (.text+0x11b6): undefined reference to `tld_check_lz'
url.c: (.text+0x11cb): undefined reference to `idn_free'
url.c: (.text+0x11d5): undefined reference to `tld_strerror'
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../libcurl.a(url.o): In function `Curl_disconnect':
url.c: (.text+0x1bd4): undefined reference to `idn_free'
url.c: (.text+0x1be6): undefined reference to `idn_free'
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../libcurl.a(ssluse.o): In function `Curl_ossl_version':
ssluse.c: (.text+0xc): undefined reference to `SSLeay'
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../libcurl.a(ssluse.o): In function `Curl_ossl_data_pending':
ssluse.c: (.text+0x262): undefined reference to `SSL_pending'
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../libcurl.a(ssluse.o): In function `x509_name_oneline':
ssluse.c: (.text+0x3d6): undefined reference to `X509_NAME_print_ex'
Are you sure that you are following the steps for generating an archive...otherwise it wont complain about external references. Post the commands you are following to generate libcurl.a and make sure that all dependencies of curl have their static lib versions installed otherwise there will be errors.
I have downloaded and untarred the curl source. I simply go to the lib sub-directory and enter "make." Everything works well, a libcurl.a is produced, and when I try to use it with g++ -static, I get these "undefined reference" errors.
It has been a while but when I last compiled it there was some "curl-config --static-lib" thing i had to specify on the comand line...is there a readme or install file with the curl distro.
It wouldn't be a switch given to make, but a switch given to the compiler. Try CFLAGS="-static" ./configure, if that doesn't work, LDFLAGS="-static" ./configure
No, and there is no reason that libcurl.a should be capable of being build that way.
As others have said, you need to (1) tell the compiler you are building a static application and (2) name all the static libraries necessary to resolve all symbols.