q96456的专栏

项目中适用libcurl,反正是开源的,那就编译就OK了,只是在使用过程中遇到了N多蛋疼问题,记录下来,为遇到同样问题的朋友提供个参考。

正常使用的编译,网上多得是列一下也

./configure –prefix=/usr/local/curl 安装的路径随便写。

make;make install

这样就搞定了。

我的问题是需要支持https,那么就需要把openssl编译进来,前提是你的系统安装了ssl,自己查查看吧,在/lib, /lib64,/usr/local,/usr/local/lib 反正自己找找,要是没有的话那恭喜你了,还得先下载或者编译openssl,这部分跳过去,我认为你有。

./configure –prefix=/usr/local/curl –with-ssl=/usr/local/ssl 假如你的ssl在/usr/local/ssl这样执行完估计就会出现SSL support: enabled (OpenSSL) 你以为你搞定了?试一下curl -V看看有么有提示找不到libssl.so吧,如果没有提示,那么你比我幸运,如果提示了,请执行下面的这个

env LDFLAGS=-R/usr/local/ssl/lib ./configure –prefix=/usr/local/curl –with-ssl=/usr/local/ssl这样基本上可以确定帮你找得到libssl.so了。

好了,可以让你的程序加载libcurl了。

什么,你还是有问题,编译过不去,提示下面这一堆乱七八糟的错误

../lib64/libcurl.a(ldap.o): In function `Curl_ldap’:ldap.c:(.text+0xa0): undefined reference to `ldap_url_parse’ldap.c:(.text+0xb8): undefined reference to `ldap_err2string’ldap.c:(.text+0xee): undefined reference to `ldap_msgfree’ldap.c:(.text+0x107): undefined reference to `ldap_free_urldesc’ldap.c:(.text+0x119): undefined reference to `ldap_unbind_s’ldap.c:(.text+0x1bf): undefined reference to `ldap_set_option’ldap.c:(.text+0x1ce): undefined reference to `ldap_set_option’ldap.c:(.text+0x1e1): undefined reference to `ldap_init’ldap.c:(.text+0x255): undefined reference to `ldap_set_option’ldap.c:(.text+0x264): undefined reference to `ldap_set_option’ldap.c:(.text+0x293): undefined reference to `ldap_simple_bind_s’ldap.c:(.text+0x2c0): undefined reference to `ldap_set_option’ldap.c:(.text+0x2e6): undefined reference to `ldap_simple_bind_s’ldap.c:(.text+0x300): undefined reference to `ldap_err2string’ldap.c:(.text+0x350): undefined reference to `ldap_search_s’ldap.c:(.text+0x369): undefined reference to `ldap_err2string’ldap.c:(.text+0x39d): undefined reference to `ldap_first_entry’ldap.c:(.text+0x3e1): undefined reference to `ldap_get_dn’ldap.c:(.text+0x44f): undefined reference to `ldap_first_attribute’ldap.c:(.text+0x46e): undefined reference to `ldap_get_values_len’ldap.c:(.text+0x5a4): undefined reference to `ldap_value_free_len’ldap.c:(.text+0x5d6): undefined reference to `ldap_memfree’ldap.c:(.text+0x5ea): undefined reference to `ldap_next_attribute’ldap.c:(.text+0x600): undefined reference to `ldap_memfree’ldap.c:(.text+0x611): undefined reference to `ber_free’ldap.c:(.text+0x620): undefined reference to `ldap_next_entry’collect2: ld returned 1 exit status

那么恭喜你,ldap的内容你的系统中找不到。反正我的系统里是找不到,我也不想用他,那么就在编译的时候把它disable掉吧,如下:

env LDFLAGS=-R/usr/local/ssl/lib ./configure –prefix=/usr/local/curl –with-ssl=/usr/local/ssl–disable-ldap –disable-ldaps

这样配置后,理论上你就吧ldap的东西屏蔽了,什么叫理论,就是TM的别人OK,,而我不行。看了一下curl的源代码,这些报错的地方在ldap.c中,而这个函数是否调用,都是根据CURL_DISABLE_LDAP这个宏能控制的,定义了这个宏,ldap的功能就彻底与你无缘了,OK,既然我配置不管用,我就直接改源代码,在curl_ldap.h中定义这个宏。重新配置编译。

再次把libcurl编译到你的工程中,OK。如果还有其他什么编译错误,那么有可能是curl中的某些选项你选了,但是系统里没有,用同样的方法搞定它。

对于旅行,从来都记忆模糊。记不得都去了哪些地方,

q96456的专栏

相关文章:

你感兴趣的文章:

标签云: