Ubuntu12.04 链接libcurl静态库

Ubuntu12.04 链接libcurl静态库


> wget http://curl.haxx.se/download/curl-7.29.0.tar.gz

> tar zxvf curl-7.29.0.tar.gz

> cd curl-7.29.0

> ./configure --prefix=/usr/local/curl --disable-shared --enable-static --without-libidn --without-ssl --without-librtmp --without-gnutls --without-nss --without-libssh2 --without-zlib --without-winidn --disable-rtsp --disable-ldap --disable-ldaps --disable-ipv6

> make

> sudo make install
> vi a.c
#include <curl/curl.h>
int main() {
printf("%s\n", curl_version());
return 0;
}

> curl-config --static-libs
/usr/local/curl/lib/libcurl.a -lrt

> gcc a.c -static $(/usr/local/curl/bin/curl-config --static-libs --cflags)


> file a.out
a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.24, BuildID[sha1]=0x251f05855bb8e2e633171019d5e6c4bcc3d80a80, not stripped

> ./a.out
libcurl/7.29.0

注意我这里不需要其它功能不需要ssl等,这里全disable掉,不然会在连接时报错:
如:url.c|| undefined reference to ‘idn_free’
我就在这里郁闷了半天。
如果你没有disable掉,但你的机器上又没有安装相应的库,link时也会报错。
./configure --prefix=/usr/local/curl --disable-shared --enable-static --without-libidn --without-ssl --without-librtmp --without-gnutls --without-nss --without-libssh2 --without-zlib --without-winidn --disable-rtsp --disable-ldap --disable-ldaps --disable-ipv6

  curl version:     7.29.0
  Host setup:       i686-pc-linux-gnu
  Install prefix:   /usr/local/curl
  Compiler:         gcc
  SSL support:      no      (--with-{ssl,gnutls,nss,polarssl,cyassl,axtls,winssl,darwinssl} )
  SSH support:      no      (--with-libssh2)
  zlib support:     no      (--with-zlib)
  krb4 support:     no      (--with-krb4*)
  GSSAPI support:   no      (--with-gssapi)
  SPNEGO support:   no      (--with-spnego)
  TLS-SRP support:  no      (--enable-tls-srp)
  resolver:         default (--enable-ares / --enable-threaded-resolver)
  ipv6 support:     no      (--enable-ipv6)
  IDN support:      no      (--with-{libidn,winidn})
  Build libcurl:    Shared=no, Static=yes
  Built-in manual:  enabled
  --libcurl option: enabled (--disable-libcurl-option)
  Verbose errors:   enabled (--disable-verbose)
  SSPI support:     no      (--enable-sspi)
  ca cert bundle:   /etc/ssl/certs/ca-certificates.crt
  ca cert path:     no
  LDAP support:     no      (--enable-ldap / --with-ldap-lib / --with-lber-lib)
  LDAPS support:    no      (--enable-ldaps)
  RTSP support:     no      (--enable-rtsp)
  RTMP support:     no      (--with-librtmp)
  metalink support: no      (--with-libmetalink)
  Protocols:        DICT FILE FTP GOPHER HTTP IMAP POP3 SMTP TELNET TFTP



   KB94248  - How To Use the C Run-Time
              http://support.microsoft.com/kb/94248/en-us

   KB140584 - How to link with the correct C Run-Time (CRT) library
              http://support.microsoft.com/kb/140584/en-us

   KB190799 - Potential Errors Passing CRT Objects Across DLL Boundaries
              http://msdn.microsoft.com/en-us/library/ms235460

猜你喜欢

转载自wangxiaoxu.iteye.com/blog/2077790
今日推荐