Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
898 views
in Technique[技术] by (71.8m points)

curl - Static linking libcurl using c

I am using Libcurl in my application with C and GNU compiler on a linux machine. Application also uses OpenSSL libraries and some other libraries. I am trying to statically link the libraries, except for lcurl linking with other libraries works fine.

I am trying to compile as below.

gcc -static -I. -o test test.c -lz -lssl -lcrypto -lcurl

Am I doing anything wrong? Is there a way to force static linking of some librairies (libc for exemple) ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Libcurl is itself linked against a ton of other libraries, most of which aren't included in your compile command line. For instance, mine (on Debian Squeeze) links against:

  • libc
  • libcom_err
  • libcrypto
  • libdl
  • libgcrypt
  • libgnutls
  • libgpg-error
  • libgssapi_krb5
  • libidn
  • libk5crypto
  • libkeyutils
  • libkrb5
  • libkrb5support
  • liblber-2.4
  • libldap_r-2.4
  • libpthread
  • libresolv
  • librt
  • libsasl2
  • libssh2
  • libssl
  • libtasn1
  • libz

(You can get a similar list for yourself by running ldd on the library on Linux, or otool -L on Darwin.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...