libcurl apps的静态编译linux C(缺少库)

时间:2012-03-10 18:16:32

标签: c linux static compilation libcurl

//to-long-didnt-read -> missing lgssapi_krb5 library and can't seem to find it

我无法使用其中一个测试应用程序静态链接libcurl。

我已阅读论坛,有人说发出“curl-config --libs”命令并包含所有这些库,但命令只返回

~/Desktop# curl-config --libs
-lcurl

他们的回归

[root@zabbix ~]# curl-config --libs
-L/usr/kerberos/lib -lcurl -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lresolv -ldl -lidn -lssl -lcrypto -lz 

我也读过这篇文章

Static linking libcurl using c

我的输出是

~/Desktop# ldd /usr/lib/libcurl.so
        linux-gate.so.1 =>  (0xb78be000)
        libidn.so.11 => /usr/lib/libidn.so.11 (0xb7837000)
        liblber-2.4.so.2 => /usr/lib/liblber-2.4.so.2 (0xb782a000)
        libldap_r-2.4.so.2 => /usr/lib/libldap_r-2.4.so.2 (0xb77e2000)
        librt.so.1 => /lib/tls/i686/cmov/librt.so.1 (0xb77d9000)
        libgssapi_krb5.so.2 => /usr/lib/libgssapi_krb5.so.2 (0xb77aa000)
        libz.so.1 => /lib/libz.so.1 (0xb7795000)
        libgnutls.so.26 => /usr/lib/libgnutls.so.26 (0xb76fa000)
        libgcrypt.so.11 => /lib/libgcrypt.so.11 (0xb7686000)
        libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb752c000)
        libresolv.so.2 => /lib/tls/i686/cmov/libresolv.so.2 (0xb7518000)
        libsasl2.so.2 => /usr/lib/libsasl2.so.2 (0xb7500000)
        libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0xb74e7000)
        /lib/ld-linux.so.2 (0xb78bf000)
        libkrb5.so.3 => /usr/lib/libkrb5.so.3 (0xb7436000)
        libk5crypto.so.3 => /usr/lib/libk5crypto.so.3 (0xb7411000)
        libcom_err.so.2 => /lib/libcom_err.so.2 (0xb740d000)
        libkrb5support.so.0 => /usr/lib/libkrb5support.so.0 (0xb7405000)
        libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7401000)
        libkeyutils.so.1 => /lib/libkeyutils.so.1 (0xb73fd000)
        libtasn1.so.3 => /usr/lib/libtasn1.so.3 (0xb73eb000)
        libgpg-error.so.0 => /lib/libgpg-error.so.0 (0xb73e6000)

当我尝试使用

编译时
~/Desktop# gcc -static test.c -o down -lcurl -lidn -llber -lldap -lrt -lgssapi_krb5 -lgssapi_krb5 -lz -lgnutls -lgcrypt

我得到了

/usr/bin/ld: cannot find -lgssapi_krb5
collect2: ld returned 1 exit status

我已经尝试搜索此库,但我似乎无法通过谷歌搜索找到它。我也尝试过apt-get缓存搜索但它没有返回任何结果。我正在运行Ubuntu并且非常感谢任何帮助。

1 个答案:

答案 0 :(得分:11)

找到了可行的工作。

$ wget http://curl.haxx.se/download/curl-7.24.0.tar.lzma
$ tar xf curl-7.24.0.tar.lzma
$ cd curl-7.24.0
$ ./configure --disable-shared --enable-static --prefix=/tmp/curl --disable-ldap --disable-sspi
$ make && make install
$ cat << EOF > a.c
#include <curl/curl.h>
int main() {
printf("%s\n", curl_version());
return 0;
}
EOF
$ gcc a.c -static $(/tmp/curl/bin/curl-config --static-libs --cflags) -ldl
$ file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.15, not stripped
$ ./a.out
libcurl/7.24.0 OpenSSL/1.0.0e zlib/1.2.3.4 libidn/1.22