Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

igorland

macrumors newbie
Original poster
Mar 4, 2014
24
0
Hello.

Did someone succeed in using libcurl statically in Xcode? I have installed libcurl using:

$ ./configure --prefix=/home/igorland/Libs/curl --disable-shared –enable-static
$ make
$make install

Then in the Header Search Paths, I include the path to the headers:
/Users/igorland/Libs/curl/include/

And in the Other Linker Flags, I include the path to the libcurl.a file:
/Users/igorland/Libs/curl/lib/libcurl.a

The file is there, but I receive linking errors:

Code:
Undefined symbols for architecture x86_64:
  "_ber_free", referenced from:
      _Curl_ldap in libcurl.a(libcurl_la-ldap.o)
  "_inflate", referenced from:
      _inflate_stream in libcurl.a(libcurl_la-content_encoding.o)
  "_inflateEnd", referenced from:
      _inflate_stream in libcurl.a(libcurl_la-content_encoding.o)
      _Curl_unencode_gzip_write in libcurl.a(libcurl_la-content_encoding.o)
      _Curl_unencode_cleanup in libcurl.a(libcurl_la-content_encoding.o)
  "_inflateInit2_", referenced from:
      _inflate_stream in libcurl.a(libcurl_la-content_encoding.o)
      _Curl_unencode_gzip_write in libcurl.a(libcurl_la-content_encoding.o)
  "_inflateInit_", referenced from:
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

My project is multi-platform, so I am compelled to use libcurl. But this is turning into a nightmare... )))

Thank you so much in advance!
 
I googled the longest of the unresolved symbols from your error messages (_inflateInit2_) and it found this article:
http://stackoverflow.com/questions/7752127/errorapple-mach-o-linker-id-warning

The suggested solution there is to link against libz.dylib. It looks like that lib will also resolve some of your other unresolved symbols.


If you want to know what other libs libcurl itself relies on, you can use the 'otool' command in Terminal:
Code:
otool -L /usr/lib/libcurl.dylib
Presumably, the dylib version of libcurl references the same external libs as the static version of libcurl.

When I run that command here, it tells me that libz.dylib is indeed referenced by libcurl.
 
When I run that command here, it tells me that libz.dylib is indeed referenced by libcurl.
I rebuilt the libcurl library and ran otool. These are the dependencies of the static libcurl:

Code:
/usr/local/lib/libcurl.a(libcurl_la-file.o):
/usr/local/lib/libcurl.a(libcurl_la-timeval.o):
/usr/local/lib/libcurl.a(libcurl_la-base64.o):
/usr/local/lib/libcurl.a(libcurl_la-hostip.o):
/usr/local/lib/libcurl.a(libcurl_la-progress.o):
/usr/local/lib/libcurl.a(libcurl_la-formdata.o):
/usr/local/lib/libcurl.a(libcurl_la-cookie.o):
/usr/local/lib/libcurl.a(libcurl_la-http.o):
/usr/local/lib/libcurl.a(libcurl_la-sendf.o):
/usr/local/lib/libcurl.a(libcurl_la-ftp.o):
/usr/local/lib/libcurl.a(libcurl_la-url.o):
/usr/local/lib/libcurl.a(libcurl_la-dict.o):
/usr/local/lib/libcurl.a(libcurl_la-if2ip.o):
/usr/local/lib/libcurl.a(libcurl_la-speedcheck.o):
/usr/local/lib/libcurl.a(libcurl_la-ldap.o):
/usr/local/lib/libcurl.a(libcurl_la-version.o):
/usr/local/lib/libcurl.a(libcurl_la-getenv.o):
/usr/local/lib/libcurl.a(libcurl_la-escape.o):
/usr/local/lib/libcurl.a(libcurl_la-mprintf.o):
/usr/local/lib/libcurl.a(libcurl_la-telnet.o):
/usr/local/lib/libcurl.a(libcurl_la-netrc.o):
/usr/local/lib/libcurl.a(libcurl_la-getinfo.o):
/usr/local/lib/libcurl.a(libcurl_la-transfer.o):
/usr/local/lib/libcurl.a(libcurl_la-strcase.o):
/usr/local/lib/libcurl.a(libcurl_la-easy.o):
/usr/local/lib/libcurl.a(libcurl_la-security.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_fnmatch.o):
/usr/local/lib/libcurl.a(libcurl_la-fileinfo.o):
/usr/local/lib/libcurl.a(libcurl_la-ftplistparser.o):
/usr/local/lib/libcurl.a(libcurl_la-wildcard.o):
/usr/local/lib/libcurl.a(libcurl_la-krb5.o):
/usr/local/lib/libcurl.a(libcurl_la-memdebug.o):
/usr/local/lib/libcurl.a(libcurl_la-http_chunks.o):
/usr/local/lib/libcurl.a(libcurl_la-strtok.o):
/usr/local/lib/libcurl.a(libcurl_la-connect.o):
/usr/local/lib/libcurl.a(libcurl_la-llist.o):
/usr/local/lib/libcurl.a(libcurl_la-hash.o):
/usr/local/lib/libcurl.a(libcurl_la-multi.o):
/usr/local/lib/libcurl.a(libcurl_la-content_encoding.o):
/usr/local/lib/libcurl.a(libcurl_la-share.o):
/usr/local/lib/libcurl.a(libcurl_la-http_digest.o):
/usr/local/lib/libcurl.a(libcurl_la-md4.o):
/usr/local/lib/libcurl.a(libcurl_la-md5.o):
/usr/local/lib/libcurl.a(libcurl_la-http_negotiate.o):
/usr/local/lib/libcurl.a(libcurl_la-inet_pton.o):
/usr/local/lib/libcurl.a(libcurl_la-strtoofft.o):
/usr/local/lib/libcurl.a(libcurl_la-strerror.o):
/usr/local/lib/libcurl.a(libcurl_la-amigaos.o):
/usr/local/lib/libcurl.a(libcurl_la-hostasyn.o):
/usr/local/lib/libcurl.a(libcurl_la-hostip4.o):
/usr/local/lib/libcurl.a(libcurl_la-hostip6.o):
/usr/local/lib/libcurl.a(libcurl_la-hostsyn.o):
/usr/local/lib/libcurl.a(libcurl_la-inet_ntop.o):
/usr/local/lib/libcurl.a(libcurl_la-parsedate.o):
/usr/local/lib/libcurl.a(libcurl_la-select.o):
/usr/local/lib/libcurl.a(libcurl_la-tftp.o):
/usr/local/lib/libcurl.a(libcurl_la-splay.o):
/usr/local/lib/libcurl.a(libcurl_la-strdup.o):
/usr/local/lib/libcurl.a(libcurl_la-socks.o):
/usr/local/lib/libcurl.a(libcurl_la-ssh.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_addrinfo.o):
/usr/local/lib/libcurl.a(libcurl_la-socks_gssapi.o):
/usr/local/lib/libcurl.a(libcurl_la-socks_sspi.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_sspi.o):
/usr/local/lib/libcurl.a(libcurl_la-slist.o):
/usr/local/lib/libcurl.a(libcurl_la-nonblock.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_memrchr.o):
/usr/local/lib/libcurl.a(libcurl_la-imap.o):
/usr/local/lib/libcurl.a(libcurl_la-pop3.o):
/usr/local/lib/libcurl.a(libcurl_la-smtp.o):
/usr/local/lib/libcurl.a(libcurl_la-pingpong.o):
/usr/local/lib/libcurl.a(libcurl_la-rtsp.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_threads.o):
/usr/local/lib/libcurl.a(libcurl_la-warnless.o):
/usr/local/lib/libcurl.a(libcurl_la-hmac.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_rtmp.o):
/usr/local/lib/libcurl.a(libcurl_la-openldap.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_gethostname.o):
/usr/local/lib/libcurl.a(libcurl_la-gopher.o):
/usr/local/lib/libcurl.a(libcurl_la-idn_win32.o):
/usr/local/lib/libcurl.a(libcurl_la-http_proxy.o):
/usr/local/lib/libcurl.a(libcurl_la-non-ascii.o):
/usr/local/lib/libcurl.a(libcurl_la-asyn-ares.o):
/usr/local/lib/libcurl.a(libcurl_la-asyn-thread.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_gssapi.o):
/usr/local/lib/libcurl.a(libcurl_la-http_ntlm.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_ntlm_wb.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_ntlm_core.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_sasl.o):
/usr/local/lib/libcurl.a(libcurl_la-rand.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_multibyte.o):
/usr/local/lib/libcurl.a(libcurl_la-hostcheck.o):
/usr/local/lib/libcurl.a(libcurl_la-conncache.o):
/usr/local/lib/libcurl.a(libcurl_la-pipeline.o):
/usr/local/lib/libcurl.a(libcurl_la-dotdot.o):
/usr/local/lib/libcurl.a(libcurl_la-x509asn1.o):
/usr/local/lib/libcurl.a(libcurl_la-http2.o):
/usr/local/lib/libcurl.a(libcurl_la-smb.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_endian.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_des.o):
/usr/local/lib/libcurl.a(libcurl_la-system_win32.o):
/usr/local/lib/libcurl.a(libcurl_la-vauth.o):
/usr/local/lib/libcurl.a(libcurl_la-cleartext.o):
/usr/local/lib/libcurl.a(libcurl_la-cram.o):
/usr/local/lib/libcurl.a(libcurl_la-digest.o):
/usr/local/lib/libcurl.a(libcurl_la-digest_sspi.o):
/usr/local/lib/libcurl.a(libcurl_la-krb5_gssapi.o):
/usr/local/lib/libcurl.a(libcurl_la-krb5_sspi.o):
/usr/local/lib/libcurl.a(libcurl_la-ntlm.o):
/usr/local/lib/libcurl.a(libcurl_la-ntlm_sspi.o):
/usr/local/lib/libcurl.a(libcurl_la-oauth2.o):
/usr/local/lib/libcurl.a(libcurl_la-spnego_gssapi.o):
/usr/local/lib/libcurl.a(libcurl_la-spnego_sspi.o):
/usr/local/lib/libcurl.a(libcurl_la-openssl.o):
/usr/local/lib/libcurl.a(libcurl_la-gtls.o):
/usr/local/lib/libcurl.a(libcurl_la-vtls.o):
/usr/local/lib/libcurl.a(libcurl_la-nss.o):
/usr/local/lib/libcurl.a(libcurl_la-polarssl.o):
/usr/local/lib/libcurl.a(libcurl_la-polarssl_threadlock.o):
/usr/local/lib/libcurl.a(libcurl_la-axtls.o):
/usr/local/lib/libcurl.a(libcurl_la-cyassl.o):
/usr/local/lib/libcurl.a(libcurl_la-schannel.o):
/usr/local/lib/libcurl.a(libcurl_la-darwinssl.o):
/usr/local/lib/libcurl.a(libcurl_la-gskit.o):
/usr/local/lib/libcurl.a(libcurl_la-mbedtls.o):
 
I rebuilt the libcurl library and ran otool. These are the dependencies of the static libcurl:

Code:
/usr/local/lib/libcurl.a(libcurl_la-file.o):
/usr/local/lib/libcurl.a(libcurl_la-timeval.o):
/usr/local/lib/libcurl.a(libcurl_la-base64.o):
/usr/local/lib/libcurl.a(libcurl_la-hostip.o):
/usr/local/lib/libcurl.a(libcurl_la-progress.o):
/usr/local/lib/libcurl.a(libcurl_la-formdata.o):
/usr/local/lib/libcurl.a(libcurl_la-cookie.o):
/usr/local/lib/libcurl.a(libcurl_la-http.o):
/usr/local/lib/libcurl.a(libcurl_la-sendf.o):
/usr/local/lib/libcurl.a(libcurl_la-ftp.o):
/usr/local/lib/libcurl.a(libcurl_la-url.o):
/usr/local/lib/libcurl.a(libcurl_la-dict.o):
/usr/local/lib/libcurl.a(libcurl_la-if2ip.o):
/usr/local/lib/libcurl.a(libcurl_la-speedcheck.o):
/usr/local/lib/libcurl.a(libcurl_la-ldap.o):
/usr/local/lib/libcurl.a(libcurl_la-version.o):
/usr/local/lib/libcurl.a(libcurl_la-getenv.o):
/usr/local/lib/libcurl.a(libcurl_la-escape.o):
/usr/local/lib/libcurl.a(libcurl_la-mprintf.o):
/usr/local/lib/libcurl.a(libcurl_la-telnet.o):
/usr/local/lib/libcurl.a(libcurl_la-netrc.o):
/usr/local/lib/libcurl.a(libcurl_la-getinfo.o):
/usr/local/lib/libcurl.a(libcurl_la-transfer.o):
/usr/local/lib/libcurl.a(libcurl_la-strcase.o):
/usr/local/lib/libcurl.a(libcurl_la-easy.o):
/usr/local/lib/libcurl.a(libcurl_la-security.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_fnmatch.o):
/usr/local/lib/libcurl.a(libcurl_la-fileinfo.o):
/usr/local/lib/libcurl.a(libcurl_la-ftplistparser.o):
/usr/local/lib/libcurl.a(libcurl_la-wildcard.o):
/usr/local/lib/libcurl.a(libcurl_la-krb5.o):
/usr/local/lib/libcurl.a(libcurl_la-memdebug.o):
/usr/local/lib/libcurl.a(libcurl_la-http_chunks.o):
/usr/local/lib/libcurl.a(libcurl_la-strtok.o):
/usr/local/lib/libcurl.a(libcurl_la-connect.o):
/usr/local/lib/libcurl.a(libcurl_la-llist.o):
/usr/local/lib/libcurl.a(libcurl_la-hash.o):
/usr/local/lib/libcurl.a(libcurl_la-multi.o):
/usr/local/lib/libcurl.a(libcurl_la-content_encoding.o):
/usr/local/lib/libcurl.a(libcurl_la-share.o):
/usr/local/lib/libcurl.a(libcurl_la-http_digest.o):
/usr/local/lib/libcurl.a(libcurl_la-md4.o):
/usr/local/lib/libcurl.a(libcurl_la-md5.o):
/usr/local/lib/libcurl.a(libcurl_la-http_negotiate.o):
/usr/local/lib/libcurl.a(libcurl_la-inet_pton.o):
/usr/local/lib/libcurl.a(libcurl_la-strtoofft.o):
/usr/local/lib/libcurl.a(libcurl_la-strerror.o):
/usr/local/lib/libcurl.a(libcurl_la-amigaos.o):
/usr/local/lib/libcurl.a(libcurl_la-hostasyn.o):
/usr/local/lib/libcurl.a(libcurl_la-hostip4.o):
/usr/local/lib/libcurl.a(libcurl_la-hostip6.o):
/usr/local/lib/libcurl.a(libcurl_la-hostsyn.o):
/usr/local/lib/libcurl.a(libcurl_la-inet_ntop.o):
/usr/local/lib/libcurl.a(libcurl_la-parsedate.o):
/usr/local/lib/libcurl.a(libcurl_la-select.o):
/usr/local/lib/libcurl.a(libcurl_la-tftp.o):
/usr/local/lib/libcurl.a(libcurl_la-splay.o):
/usr/local/lib/libcurl.a(libcurl_la-strdup.o):
/usr/local/lib/libcurl.a(libcurl_la-socks.o):
/usr/local/lib/libcurl.a(libcurl_la-ssh.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_addrinfo.o):
/usr/local/lib/libcurl.a(libcurl_la-socks_gssapi.o):
/usr/local/lib/libcurl.a(libcurl_la-socks_sspi.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_sspi.o):
/usr/local/lib/libcurl.a(libcurl_la-slist.o):
/usr/local/lib/libcurl.a(libcurl_la-nonblock.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_memrchr.o):
/usr/local/lib/libcurl.a(libcurl_la-imap.o):
/usr/local/lib/libcurl.a(libcurl_la-pop3.o):
/usr/local/lib/libcurl.a(libcurl_la-smtp.o):
/usr/local/lib/libcurl.a(libcurl_la-pingpong.o):
/usr/local/lib/libcurl.a(libcurl_la-rtsp.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_threads.o):
/usr/local/lib/libcurl.a(libcurl_la-warnless.o):
/usr/local/lib/libcurl.a(libcurl_la-hmac.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_rtmp.o):
/usr/local/lib/libcurl.a(libcurl_la-openldap.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_gethostname.o):
/usr/local/lib/libcurl.a(libcurl_la-gopher.o):
/usr/local/lib/libcurl.a(libcurl_la-idn_win32.o):
/usr/local/lib/libcurl.a(libcurl_la-http_proxy.o):
/usr/local/lib/libcurl.a(libcurl_la-non-ascii.o):
/usr/local/lib/libcurl.a(libcurl_la-asyn-ares.o):
/usr/local/lib/libcurl.a(libcurl_la-asyn-thread.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_gssapi.o):
/usr/local/lib/libcurl.a(libcurl_la-http_ntlm.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_ntlm_wb.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_ntlm_core.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_sasl.o):
/usr/local/lib/libcurl.a(libcurl_la-rand.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_multibyte.o):
/usr/local/lib/libcurl.a(libcurl_la-hostcheck.o):
/usr/local/lib/libcurl.a(libcurl_la-conncache.o):
/usr/local/lib/libcurl.a(libcurl_la-pipeline.o):
/usr/local/lib/libcurl.a(libcurl_la-dotdot.o):
/usr/local/lib/libcurl.a(libcurl_la-x509asn1.o):
/usr/local/lib/libcurl.a(libcurl_la-http2.o):
/usr/local/lib/libcurl.a(libcurl_la-smb.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_endian.o):
/usr/local/lib/libcurl.a(libcurl_la-curl_des.o):
/usr/local/lib/libcurl.a(libcurl_la-system_win32.o):
/usr/local/lib/libcurl.a(libcurl_la-vauth.o):
/usr/local/lib/libcurl.a(libcurl_la-cleartext.o):
/usr/local/lib/libcurl.a(libcurl_la-cram.o):
/usr/local/lib/libcurl.a(libcurl_la-digest.o):
/usr/local/lib/libcurl.a(libcurl_la-digest_sspi.o):
/usr/local/lib/libcurl.a(libcurl_la-krb5_gssapi.o):
/usr/local/lib/libcurl.a(libcurl_la-krb5_sspi.o):
/usr/local/lib/libcurl.a(libcurl_la-ntlm.o):
/usr/local/lib/libcurl.a(libcurl_la-ntlm_sspi.o):
/usr/local/lib/libcurl.a(libcurl_la-oauth2.o):
/usr/local/lib/libcurl.a(libcurl_la-spnego_gssapi.o):
/usr/local/lib/libcurl.a(libcurl_la-spnego_sspi.o):
/usr/local/lib/libcurl.a(libcurl_la-openssl.o):
/usr/local/lib/libcurl.a(libcurl_la-gtls.o):
/usr/local/lib/libcurl.a(libcurl_la-vtls.o):
/usr/local/lib/libcurl.a(libcurl_la-nss.o):
/usr/local/lib/libcurl.a(libcurl_la-polarssl.o):
/usr/local/lib/libcurl.a(libcurl_la-polarssl_threadlock.o):
/usr/local/lib/libcurl.a(libcurl_la-axtls.o):
/usr/local/lib/libcurl.a(libcurl_la-cyassl.o):
/usr/local/lib/libcurl.a(libcurl_la-schannel.o):
/usr/local/lib/libcurl.a(libcurl_la-darwinssl.o):
/usr/local/lib/libcurl.a(libcurl_la-gskit.o):
/usr/local/lib/libcurl.a(libcurl_la-mbedtls.o):
Running otool on the static library is unlikely to provide anything useful. The evidence above confirms this.

The goal here is simply to discover the libraries that libcurl itself depends on.

The ways I can think of to do this are:
1. It might be in libcurl's documentation.
2. If libcurl has a makefile, it's almost certainly in there.
3. It would be embedded in libcurl.dylib.

If you haven't checked libcurl's documentation, you can try that.
EDIT
I googled the search terms: libcurl external libraries
The top hit was this page, which lists all of curl's library dependencies:
https://curl.haxx.se/docs/libs.html

So given the libs named there, you'll need to add them to the list of libraries that your app links with. Doing this should resolve all the unresolved symbols from libcurl. If it doesn't, post the error message.

Note: That list is for 'curl' the command-line-tool, not libcurl the library. You can probably omit some of the libraries named in that list. Exactly which ones to omit can be discovered by running otool on libcurl.dylib, or looking in libcurl's makefile, or possibly a more detailed search of libcurl's documentation.​


If there was a makefile included with libcurl's source, then it's almost certain that the external libraries libcurl needs will be named there. The reason this is almost certain is that unresolved symbols would prevent libcurl.dylib from linking correctly. Therefore, every external library dependency needed to link libcurl.dylib would have to be in the makefile. The fact that you want to statically link libcurl is irrelevant here. You're only trying to discover what other libs libcurl needs. Once you have all those other libs at hand, then libcurl will correctly link, for both dylib and static versions.
 
Last edited:
Thank you, chown33! That was a very well explained response! Just an update. Firstly, I managed to solve the problem by rebuilding libucrl with the following command: --without-libidn –without-zlib –disable-ldap.
However, I've now faced another one. I am building a plugin for some software that can be several years old and, thus, may be 32-bit. So, my newly built libcurl runs fine under 64-bit. I have created another copy of libcurl.a and built it for the 32-bit architecture. Unfortunately, for some reason, this is not working. Xcode writes that the project compiled successfully but it does not create the final product. Anyways, my current preference is to go with the libcurl dynamic library that comes with Xcode -- it works fine in the universal architecture. However, my understanding is that since it will be linked with the dynamic libcurl library, I will need to bundle it with the plugin. That is what I was trying to avoid with including static libcurl.
Cheers!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.