linux下源码编译curl报错.
(2012-12-19 15:12:22)
标签:
linuxit |
分类: Linux/Unix |
说明: 由于现网的php不带curl功能, 需要编译生成一个libcurl.so给php生成curl.so模块用.
并且需要支持openssl.
编译的过程并不顺利, 这里做下记录备忘.
使用如下configure命令生成配置文件. ssl是提前编译好的openssl.
./configure
--prefix=/home/nemo/progs/curl
--with-ssl=/home/nemo/progs/ssl
问题1编译报错:
Making all in src
make[1]: Entering directory `/data/home/nemo/libs/curl-7.27.0/src'
make all-am
make[2]: Entering directory `/data/home/nemo/libs/curl-7.27.0/src'
/bin/sh ../libtool --tag=CC --mode=link gcc -g0
-O2
-Wno-system-headers
-L/home/nemo/progs/ssl/lib -o curl hugehelp.o
tool_binmode.o tool_bname.o tool_cb_dbg.o tool_cb_hdr.o
tool_cb_prg.o tool_cb_rea.o tool_cb_see.o tool_cb_wrt.o
tool_cfgable.o tool_convert.o tool_dirhie.o tool_doswin.o
tool_easysrc.o tool_formparse.o tool_getparam.o tool_getpass.o
tool_help.o tool_helpers.o tool_homedir.o tool_libinfo.o
tool_main.o tool_metalink.o tool_mfiles.o tool_msgs.o
tool_operate.o tool_operhlp.o tool_panykey.o tool_paramhlp.o
tool_parsecfg.o tool_setopt.o tool_sleep.o tool_urlglob.o
tool_util.o tool_vms.o tool_writeenv.o tool_writeout.o tool_xattr.o
strtoofft.o strdup.o rawstr.o nonblock.o
../lib/libcurl.la -lrt -lz
libtool: link: gcc -g0 -O2 -Wno-system-headers -o .libs/curl hugehelp.o tool_binmode.o tool_bname.o tool_cb_dbg.o tool_cb_hdr.o tool_cb_prg.o tool_cb_rea.o tool_cb_see.o tool_cb_wrt.o tool_cfgable.o tool_convert.o tool_dirhie.o tool_doswin.o tool_easysrc.o tool_formparse.o tool_getparam.o tool_getpass.o tool_help.o tool_helpers.o tool_homedir.o tool_libinfo.o tool_main.o tool_metalink.o tool_mfiles.o tool_msgs.o tool_operate.o tool_operhlp.o tool_panykey.o tool_paramhlp.o tool_parsecfg.o tool_setopt.o tool_sleep.o tool_urlglob.o tool_util.o tool_vms.o tool_writeenv.o tool_writeout.o tool_xattr.o strtoofft.o strdup.o rawstr.o nonblock.o
-L/home/nemo/progs/ssl/lib ../lib/.libs/libcurl.so -lrt -lz
-Wl,-rpath -Wl,/home/nemo/progs/curl/lib
../lib/.libs/libcurl.so: undefined reference
to `EVP_enc_null'
../lib/.libs/libcurl.so: undefined reference
to `COMP_compress_block'
../lib/.libs/libcurl.so: undefined reference
to `COMP_CTX_new'
../lib/.libs/libcurl.so: undefined reference
to `SRP_Calc_B'
../lib/.libs/libcurl.so: undefined reference
to `BIO_s_socket'
../lib/.libs/libcurl.so: undefined reference
to `pqueue_next'
../lib/.libs/libcurl.so: undefined reference
to `pqueue_insert'
../lib/.libs/libcurl.so: undefined reference
to `SRP_check_known_gN_param'
../lib/.libs/libcurl.so: undefined reference
to `COMP_expand_block'
../lib/.libs/libcurl.so: undefined reference
to `pqueue_peek'
../lib/.libs/libcurl.so: undefined reference
to `SRP_Calc_x'
../lib/.libs/libcurl.so: undefined reference
to `pqueue_free'
../lib/.libs/libcurl.so: undefined reference
to `OPENSSL_DIR_read'
../lib/.libs/libcurl.so: undefined reference
to `SRP_Calc_client_key'
../lib/.libs/libcurl.so: undefined reference
to `X509_STORE_set_default_paths'
../lib/.libs/libcurl.so: undefined reference
to `COMP_CTX_free'
../lib/.libs/libcurl.so: undefined reference
to `pqueue_find'
../lib/.libs/libcurl.so: undefined reference
to `pqueue_pop'
../lib/.libs/libcurl.so: undefined reference
to `pitem_free'
../lib/.libs/libcurl.so: undefined reference
to `SRP_create_verifier_BN'
../lib/.libs/libcurl.so: undefined reference
to `SRP_Verify_B_mod_N'
../lib/.libs/libcurl.so: undefined reference
to `pqueue_iterator'
../lib/.libs/libcurl.so: undefined reference
to `SRP_get_default_gN'
../lib/.libs/libcurl.so: undefined reference
to `pqueue_size'
../lib/.libs/libcurl.so: undefined reference
to `X509_certificate_type'
../lib/.libs/libcurl.so: undefined reference
to `SRP_Calc_server_key'
../lib/.libs/libcurl.so: undefined reference
to `SRP_Verify_A_mod_N'
../lib/.libs/libcurl.so: undefined reference
to `SRP_Calc_A'
../lib/.libs/libcurl.so: undefined reference
to `pqueue_new'
../lib/.libs/libcurl.so: undefined reference
to `SRP_Calc_u'
../lib/.libs/libcurl.so: undefined reference
to `OPENSSL_DIR_end'
../lib/.libs/libcurl.so: undefined reference
to `COMP_zlib'
../lib/.libs/libcurl.so: undefined reference
to `ERR_load_crypto_strings'
../lib/.libs/libcurl.so: undefined reference
to `X509_STORE_load_locations'
../lib/.libs/libcurl.so: undefined reference
to `pitem_new'
collect2: ld returned 1 exit status
make[2]: *** [curl] Error 1
make[2]: Leaving directory `/data/home/nemo/libs/curl-7.27.0/src'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/data/home/nemo/libs/curl-7.27.0/src'
make: *** [all-recursive] Error 1
分析:
1) 这些报错未定义的符号是什么符号? 是属于哪个库的? 是openssl的吗? (可以通过nm ssl的so或库查看)
经查是, crypto库的
2) 那么crypto库在哪里? 有没有默认链接进来?
经查是个crypto.a文件,
放在了ssl的编译号的同级目录里 :
/home/nemo/progs/ssl/lib/libcrypto.a
另外, 系统默认也带了crypto
: /usr/local/ssl/lib/libcrypto.a
另外, 查看编译链接的选项, 指定了对应的目录,
-L/home/nemo/progs/ssl/lib
但是却没有指定 -lcrypto
?!!!
解决: 进入src目录, 手动执行链接命令, 在最后补上
crypto 即可通过.
/bin/sh ../libtool --tag=CC
--mode=link gcc -g0 -O2
-Wno-system-headers
-L/home/nemo/progs/ssl/lib -o curl hugehelp.o
tool_binmode.o tool_bname.o tool_cb_dbg.o tool_cb_hdr.o
tool_cb_prg.o tool_cb_rea.o tool_cb_see.o tool_cb_wrt.o
tool_cfgable.o tool_convert.o tool_dirhie.o tool_doswin.o
tool_easysrc.o tool_formparse.o tool_getparam.o tool_getpass.o
tool_help.o tool_helpers.o tool_homedir.o tool_libinfo.o
tool_main.o tool_metalink.o tool_mfiles.o tool_msgs.o
tool_operate.o tool_operhlp.o tool_panykey.o tool_paramhlp.o
tool_parsecfg.o tool_setopt.o tool_sleep.o tool_urlglob.o
tool_util.o tool_vms.o tool_writeenv.o tool_writeout.o tool_xattr.o
strtoofft.o strdup.o rawstr.o nonblock.o
../lib/libcurl.la -lrt -lz -lcrypto
问题2
发现编译出来的libcurl.so虽然成功编译出来了, 通过ldd -r 查看, 仍然包含了很多未定义的符号, 就像上面的编译curl可执行文件报错的符号一样.
nemo@ISD_36_57_sles10sp1:[curl-7.20.1]$ ldd -r ./lib/.libs/libcurl.so
undefined symbol:
X509_certificate_type
(./lib/.libs/libcurl.so)
undefined symbol:
COMP_CTX_free
(./lib/.libs/libcurl.so)
undefined symbol:
COMP_CTX_new
(./lib/.libs/libcurl.so)
undefined symbol:
COMP_compress_block
(./lib/.libs/libcurl.so)
undefined symbol:
COMP_expand_block
(./lib/.libs/libcurl.so)
undefined symbol:
pqueue_find
(./lib/.libs/libcurl.so)
undefined symbol:
pitem_new
(./lib/.libs/libcurl.so)
undefined symbol:
pqueue_insert
(./lib/.libs/libcurl.so)
undefined symbol:
pqueue_iterator
(./lib/.libs/libcurl.so)
undefined symbol:
pqueue_next
(./lib/.libs/libcurl.so)
undefined symbol:
pitem_free
(./lib/.libs/libcurl.so)
undefined symbol:
pqueue_pop
(./lib/.libs/libcurl.so)
undefined symbol:
pqueue_peek
(./lib/.libs/libcurl.so)
undefined symbol:
X509_STORE_load_locations
(./lib/.libs/libcurl.so)
undefined symbol:
X509_STORE_set_default_paths
(./lib/.libs/libcurl.so)
undefined symbol:
BIO_s_socket
(./lib/.libs/libcurl.so)
undefined symbol:
ERR_load_crypto_strings
(./lib/.libs/libcurl.so)
undefined symbol: OPENSSL_DIR_read
(./lib/.libs/libcurl.so)
undefined symbol: OPENSSL_DIR_end
(./lib/.libs/libcurl.so)
linux-gate.so.1 =>
(0xbfffe000)
librt.so.1
=> /lib/librt.so.1 (0xb7cf4000)
libdl.so.2
=> /lib/libdl.so.2 (0xb7cf0000)
libz.so.1
=> /lib/libz.so.1 (0xb7cde000)
libc.so.6
=> /lib/libc.so.6 (0xb7bbd000)
libpthread.so.0 => /lib/libpthread.so.0
(0xb7ba9000)
/lib/ld-linux.so.2 (0x80000000)
undefined symbol:
COMP_zlib
(./lib/.libs/libcurl.so)
undefined symbol:
EVP_enc_null
(./lib/.libs/libcurl.so)
undefined symbol:
SRP_Calc_A
(./lib/.libs/libcurl.so)
undefined symbol:
SRP_check_known_gN_param
(./lib/.libs/libcurl.so)
undefined symbol:
SRP_Verify_B_mod_N
(./lib/.libs/libcurl.so)
undefined symbol:
SRP_Calc_u
(./lib/.libs/libcurl.so)
undefined symbol:
SRP_Calc_x
(./lib/.libs/libcurl.so)
undefined symbol:
SRP_Calc_client_key
(./lib/.libs/libcurl.so)
undefined symbol:
SRP_Verify_A_mod_N
(./lib/.libs/libcurl.so)
undefined symbol:
SRP_Calc_server_key
(./lib/.libs/libcurl.so)
undefined symbol:
SRP_get_default_gN
(./lib/.libs/libcurl.so)
undefined symbol:
SRP_create_verifier_BN
(./lib/.libs/libcurl.so)
undefined symbol:
SRP_Calc_B
(./lib/.libs/libcurl.so)
undefined symbol:
pqueue_free
(./lib/.libs/libcurl.so)
undefined symbol:
pqueue_new
(./lib/.libs/libcurl.so)
undefined symbol:
pqueue_size
(./lib/.libs/libcurl.so
分析:
经过把整个make的成
>make.log 2>&1, 定向到文件里面,
发现make.log有如下可疑的地方.
... //
省了好多.
-L/home/nemo/progs/ssl/lib -lrt -lcrypto -lssl
-ldl -lz -O2
-Wl,-soname -Wl,libcurl.so.4 -o
.libs/libcurl.so.4.2.0
-lcrypto
-lssl , crypto居然放在ssl的前面 ? 如果ssl依赖crypto, 应该ssl放在前面才对.
解决:
进入lib目录,
修改Makefile
LIBCURL_LIBS
= -lssl -lcrypto -lrt -lcrypto -lssl -ldl -lz
=>
LIBCURL_LIBS
= -lssl -lcrypto -lrt -ldl -lz 即可.
总结, 编译生成curl时, 需手动命令行加入 -lcrypto编译;(改Makefile不管用) 变成生成libcurl.so时, 可以修改Makefile编译.
使用如下configure命令生成配置文件. ssl是提前编译好的openssl.
问题1编译报错:
Making all in src
make[1]: Entering directory `/data/home/nemo/libs/curl-7.27.0/src'
make
make[2]: Entering directory `/data/home/nemo/libs/curl-7.27.0/src'
/bin/sh ../libtool --tag=CC --mode=link gcc
libtool: link: gcc -g0 -O2 -Wno-system-headers -o .libs/curl hugehelp.o tool_binmode.o tool_bname.o tool_cb_dbg.o tool_cb_hdr.o tool_cb_prg.o tool_cb_rea.o tool_cb_see.o tool_cb_wrt.o tool_cfgable.o tool_convert.o tool_dirhie.o tool_doswin.o tool_easysrc.o tool_formparse.o tool_getparam.o tool_getpass.o tool_help.o tool_helpers.o tool_homedir.o tool_libinfo.o tool_main.o tool_metalink.o tool_mfiles.o tool_msgs.o tool_operate.o tool_operhlp.o tool_panykey.o tool_paramhlp.o tool_parsecfg.o tool_setopt.o tool_sleep.o tool_urlglob.o tool_util.o tool_vms.o tool_writeenv.o tool_writeout.o tool_xattr.o strtoofft.o strdup.o rawstr.o nonblock.o
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
../lib/.libs/libcurl.so:
collect2: ld returned 1 exit status
make[2]: *** [curl] Error 1
make[2]: Leaving directory `/data/home/nemo/libs/curl-7.27.0/src'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/data/home/nemo/libs/curl-7.27.0/src'
make: *** [all-recursive] Error 1
分析:
1) 这些报错未定义的符号是什么符号? 是属于哪个库的? 是openssl的吗? (可以通过nm ssl的so或库查看)
2) 那么crypto库在哪里? 有没有默认链接进来?
问题2
发现编译出来的libcurl.so虽然成功编译出来了, 通过ldd -r 查看, 仍然包含了很多未定义的符号, 就像上面的编译curl可执行文件报错的符号一样.
nemo@ISD_36_57_sles10sp1:[curl-7.20.1]$ ldd -r ./lib/.libs/libcurl.so
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
分析:
解决:
总结, 编译生成curl时, 需手动命令行加入 -lcrypto编译;(改Makefile不管用) 变成生成libcurl.so时, 可以修改Makefile编译.