libcurl linux 静态链接库_Linux ubuntu OpenSSL + curl 静态库编译及使用

  • Post author:
  • Post category:linux


下载源码

源码编译

解压之后,进入源码目录openssl-1.1.0f,执行如下命令。因为只需要编译静态库,也没有特殊要求,所以使用的编译选项配置很简单:

./config -fPIC no-shared –prefix=/home/aa/Downloads/linux

make all

make install

–prefix  用来指定输出目录  ,-fPIC:指示生成位置无关的代码,这个选项是在把openssl生成的静态库链接到动态库的时候提示错误添加的;no-shared:指示生成静态库。

最终在指定目录下会编译出libssl.a和libcrypto.a两个库文件,在开发的时候只需要包含头件并链接这两个库就可以了。

附录:

关于openssl的编译选项的解读:

全局选项

第一类是全局性选项:

–openssldir=OPENSSLDIR 安装目录,默认是 /usr/local/ssl 。

–prefix=PREFIX 设置 lib include bin 目录的前缀,默认为 OPENSSLDIR 目录。

–install_prefix=DESTDIR 设置安装时以此目录作为”根”目录,通常用于打包,默认为空。

zlibzlib-dynamicno-zlib 使用静态的zlib压缩库、使用动态的zlib压缩库、不使用zlib压缩功能。

threadsno-threads 是否编译支持多线程的库。默认支持。

sharedno-shared 是否生成动态连接库。

asmno-asm 是否在编译过程中使用汇编代码加快编译过程。

enable-sse2no-sse2 启用/禁用SSE2指令集加速。如果你的CPU支持SSE2指令集,就可以打开,否则就要关闭。

gmpno-gmp 启用/禁用GMP库

rfc3779no-rfc3779 启用/禁用实现X509v3证书的IP地址扩展

krb5no-krb5 启用/禁用 Kerberos 5 支持

sslno-sslssl2ssl3no-ssl2no-ssl3tlsno-tls 启用/禁用 SSL(包含了SSL2/SSL3) TLS 协议支持。

dsono-dso 启用/禁用调用其它动态链接库的功能。[提示]no-dso仅在no-shared的前提下可用。

[提示]为了安装Apache的mod_ssl成功,SSLv2/SSLv3/TLS都必须开启。

算法选项

第二类用于禁用crypto目录下相应的子目录(主要是各种算法)。虽然理论上这些子目录都可以通过”no-*”语法禁用,但是实际上,为了能够最小安装libcrypto,libssl,openssl,其中的大部分目录都必须保留,实际可选的目录仅有如下这些:

no-md2,no-md4,no-mdc2,no-ripemd 这些都是摘要算法,含义一目了然。

no-des,no-rc2,no-rc4,no-rc5,no-idea,no-bf,no-cast,no-camellia 这些都是对称加密算法,含义一目了然。”bf”是”Blowfish”的意思。

no-ec,no-dsa,no-ecdsa,no-dh,no-ecdh 这些都是不对称加密算法,含义一目了然。

no-comp 数据压缩算法。因为目前实际上并没有压缩算法,所以只是定义了一些空接口。

no-store 对象存储功能。

CURL

1.下载,解压;进入目录;将上面openssl 输出的整个目录,命名 openssl 拷贝到 curl 目录下;

2.编译:

./configure –prefix=/home/aa/Downloads/linux –with-ssl=$(pwd)/openssl –disable-shared

./configure –prefix=/home/program/linux/libs –with-ssl=/usr/local/openssl –disable-shared

–prefix指定输出目录;–with-ssl=./openssl 指定 openssl 目录;

make all

make install

openssl静态库libcrypto.a和libssl.a出现undefined reference to错误的问题

libs/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup’:dso_dlfcn.c:(.text+0x11): undefined reference to `dlopen’dso_dlfcn.c:(.text+0x24): undefined reference to `dlsym’dso_dlfcn.c:(.text+0x2f): undefined reference to `dlclose’libs/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func’:dso_dlfcn.c:(.text+0x334): undefined reference to `dlsym’dso_dlfcn.c:(.text+0x3f2): undefined reference to `dlerror’libs/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load’:dso_dlfcn.c:(.text+0x459): undefined reference to `dlopen’dso_dlfcn.c:(.text+0x4c9): undefined reference to `dlclose’dso_dlfcn.c:(.text+0x502): undefined reference to `dlerror’libs/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr’:dso_dlfcn.c:(.text+0x5a1): undefined reference to `dladdr’dso_dlfcn.c:(.text+0x601): undefined reference to `dlerror’libs/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload’:dso_dlfcn.c:(.text+0x662): undefined reference to `dlclose

async.c:(.text+0xe4): undefined reference to `pthread_setspecific’async.c:(.text+0xf4): undefined reference to `pthread_getspecific’async.c:(.text+0x104): undefined reference to `pthread_setspecific’/usr/local/openssl/lib/libcrypto.a(async.o): In function `ASYNC_init_thread.part.1′:async.c:(.text+0x253): undefined reference to `pthread_setspecific’/usr/local/openssl/lib/libcrypto.a(async.o): In function `async_start_func’:async.c:(.text+0x36f): undefined reference to `pthread_getspecific’async.c:(.text+0x39e): undefined reference to `pthread_getspecific’/usr/local/openssl/lib/libcrypto.a(async.o): In function `ASYNC_start_job’:async.c:(.text+0x404): undefined reference to `pthread_getspecific’async.c:(.text+0x41e): undefined reference to `pthread_getspecific’async.c:(.text+0x433): undefined reference to `pthread_getspecific’/usr/local/openssl/lib/libcrypto.a(async.o):async.c:(.text+0x44c): more undefined references to `pthread_getspecific’ follow/usr/local/openssl/lib/libcrypto.a(async.o): In function `ASYNC_start_job’:async.c:(.text+0x7ef): undefined reference to `pthread_setspecific’async.c:(.text+0x811): undefined reference to `pthread_getspecific’async.c:(.text+0x82d): undefined reference to `pthread_getspecific’async.c:(.text+0x83f): undefined reference to `pthread_getspecific’async.c:(.text+0x870): undefined reference to `pthread_getspecific’async.c:(.text+0x891): undefined reference to `pthread_getspecific’/usr/local/openssl/lib/libcrypto.a(async.o):async.c:(.text+0x8a6): more undefined references to `pthread_getspecific’ follow/usr/local/openssl/lib/libcrypto.a(async_posix.o): In function `async_global_init’:async_posix.c:(.text+0xc): undefined reference to `pthread_key_create’async_posix.c:(.text+0x1e): undefined reference to `pthread_key_create’/usr/local/openssl/lib/libcrypto.a(async_posix.o): In function `async_local_init’:async_posix.c:(.text+0x3d): undefined reference to `pthread_setspecific’async_posix.c:(.text+0x50): undefined reference to `pthread_setspecific’/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup’:

在CMakeList

set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -v -Wall   -std=c++11”)

添加 -ldl -lpthread

plus:

curl master: https://github.com/curl/curl.gitcmake3 ../ -DBUILD_SHARED_LIBS=0 -DOPENSSL_ROOT_DIR=/data/code/openssl

posted on 2020-08-07 16:52 长戟十三千 阅读(122) 评论(0)  编辑 收藏 引用



版权声明:本文为weixin_39634985原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。