# Even the Static cURL Library Isn't Static

**URL:** <https://community.unix.com/t/even-the-static-curl-library-isnt-static/291085>\
**Category:** Programming\
**Created:** [July 6, 2011, 9:51pm UTC](https://community.unix.com/t/even-the-static-curl-library-isnt-static/291085 "2011-07-06T21:51:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrandonShw](https://community.unix.com/user_avatar/community.unix.com/brandonshw/32/6976_2.png) [@BrandonShw](https://community.unix.com/u/BrandonShw)\
**Post date:** [July 6, 2011, 9:51pm UTC](https://community.unix.com/t/even-the-static-curl-library-isnt-static/291085/1 "2011-07-06T21:51:22Z")

</div>

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.

Brandon  
.AOLWebSuite .AOLPicturesFullSizeLink { height: 1px; width: 1px; overflow: hidden; } .AOLWebSuite a {color:blue; text-decoration: underline; cursor: pointer} .AOLWebSuite a.hsSig {cursor: default}

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [July 6, 2011, 10:47pm UTC](https://community.unix.com/t/even-the-static-curl-library-isnt-static/291085/2 "2011-07-06T22:47:43Z")

</div>

It's not all static because you said you didn't want that. As a result you have to link in libraries libcurl uses.

I remember your thread. Didn't you try -ldl like suggested? All the symbols you mentioned came from it.

---

<div class="post-metadata">

**Author:** ![BrandonShw](https://community.unix.com/user_avatar/community.unix.com/brandonshw/32/6976_2.png) [@BrandonShw](https://community.unix.com/u/BrandonShw)\
**Post date:** [July 7, 2011, 11:05am UTC](https://community.unix.com/t/even-the-static-curl-library-isnt-static/291085/3 "2011-07-07T11:05:04Z")

</div>

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:

```nohighlight
/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'

```

---

<div class="post-metadata">

**Author:** ![shamrock](https://community.unix.com/letter_avatar/shamrock/32/5_5575768a8748004e209b776fc1b2916d.png) [@shamrock](https://community.unix.com/u/shamrock)\
**Post date:** [July 7, 2011, 11:10am UTC](https://community.unix.com/t/even-the-static-curl-library-isnt-static/291085/4 "2011-07-07T11:10:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BrandonShw](https://community.unix.com/user_avatar/community.unix.com/brandonshw/32/6976_2.png) [@BrandonShw](https://community.unix.com/u/BrandonShw)\
**Post date:** [July 7, 2011, 12:04pm UTC](https://community.unix.com/t/even-the-static-curl-library-isnt-static/291085/5 "2011-07-07T12:04:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![shamrock](https://community.unix.com/letter_avatar/shamrock/32/5_5575768a8748004e209b776fc1b2916d.png) [@shamrock](https://community.unix.com/u/shamrock)\
**Post date:** [July 7, 2011, 12:21pm UTC](https://community.unix.com/t/even-the-static-curl-library-isnt-static/291085/6 "2011-07-07T12:21:49Z")

</div>

> [@brandonshw](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![BrandonShw](https://community.unix.com/user_avatar/community.unix.com/brandonshw/32/6976_2.png) [@BrandonShw](https://community.unix.com/u/BrandonShw)\
**Post date:** [July 7, 2011, 3:07pm UTC](https://community.unix.com/t/even-the-static-curl-library-isnt-static/291085/7 "2011-07-07T15:07:53Z")

</div>

Thanks. By the way, I was incorrect when I said that I went into the lib sub-directory. I used the make command at the top level.

---------- Post updated at 03:07 PM ---------- Previous update was at 03:07 PM ----------

Does anybody know of a switch to put on the libcurl make to build a truly self-sufficient (static) libcurl.a which has no dependencies?

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [July 7, 2011, 11:02pm UTC](https://community.unix.com/t/even-the-static-curl-library-isnt-static/291085/8 "2011-07-07T23:02:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fpmurphy](https://community.unix.com/user_avatar/community.unix.com/fpmurphy/32/110_2.png) [@fpmurphy](https://community.unix.com/u/fpmurphy)\
**Post date:** [July 8, 2011, 11:57am UTC](https://community.unix.com/t/even-the-static-curl-library-isnt-static/291085/9 "2011-07-08T11:57:50Z")

</div>

> [@](#):
>
> Does anybody know of a switch to put on the libcurl make to build a truly self-sufficient (static) libcurl.a which has no dependencies?

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.
