解决引用openssl静态库libcrypto.a和libssl.a出现undefined reference to错误的问题
最近在做使用openssl链接http和https的项目,编译时出现以下问题。
/usr/local/openssl/lib/libcrypto.a(async.o): In function `async_free_pool_internal':
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':
dso_dlfcn.c:(.text+0x21): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x34): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x3f): undefined reference to `dlclose'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
dso_dlfcn.c:(.text+0x354): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x3fb): undefined reference to `dlerror'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
dso_dlfcn.c:(.text+0x474): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x52e): undefined reference to `dlerror'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
dso_dlfcn.c:(.text+0x5a4): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x60b): undefined reference to `dlclose'
dso_dlfcn.c:(.text+0x638): undefined reference to `dlerror'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr':
dso_dlfcn.c:(.text+0x6ce): undefined reference to `dladdr'
dso_dlfcn.c:(.text+0x731): undefined reference to `dlerror'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
dso_dlfcn.c:(.text+0x78a): undefined reference to `dlclose'
解决方案:
=======================================================================================================
gcc obj/Debug/main.o -L/usr/local/openssl/lib -lssl -lcrypto -ldl -lpthread -o main
原因分析:
在链接这个库的时候一定要注意2个问题:
1.openssl库的版本问题,请直接链到你需要的openssl库路径,比如我的就是/usr/local/openssl/lib,
2.注意-lssl -lcrypto要写在-ldl -lpthread前面,这四个必须要。
相关知识:
-L :此选项是指定链接库的文件夹地址
-l(小写的L):-lssl 即是寻找/usr/local/openssl/lib目录下的 libssl.a 这个库,编译器会自动寻找 libssl.a或者libssl.so
-I(大写的i):指定头文件的文件夹地址
解决引用openssl静态库libcrypto.a和libssl.a出现undefined reference to错误的问题的更多相关文章
- iOS 支持arm_64 和 x86_64 的OpenSSL 静态库(libcrypto.a, libssl.a)
下载链接
- android ndk-build 编译静态库libxx.a 以及Android studio openssl 静态库配置(cmake)
android ndk-build 编译静态库libxx.a 需求场景: 目前有安卓编码好的现在的openssl的两个.a,我们需要调用openssl的函数,并把功能再封装成.a; 这样使用时,在an ...
- 【转】iOS编译OpenSSL静态库(使用脚本自动编译)
原文网址:https://www.jianshu.com/p/651513cab181 本篇文章为大家推荐两个脚本,用来iOS系统下编译OpenSSL通用库,如果想了解编译具体过程,请参看<iO ...
- [转]在VS2010 VC++项目中引用Lib静态库(以Openssl为例)
本文转自:http://kb.cnblogs.com/page/94467/ Openssl是个为网络通信提供安全及数据完整性的一种安全协议,囊括了主要的密码算法.常用的密钥和证书封装管理功能以及SS ...
- IOS引用的静态库里包含category文件出现“unrecognized selector”的解决办法
来自链接:http://blog.csdn.net/ccf0703/article/details/8279187 针对静态库工程中的Category,在被其他工程引入的时候,会出现selector ...
- android编译openssl静态库.a
github上有一个开源项目,已经为你编译openssl建好了工程. 地址:https://github.com/aluvalasuman/OpenSSL1.0.1cForAndroid 选择需要的版 ...
- VS2010编译链接openssl静态库
最近工作需要使用一些加密算法.之前尝试过cryptopp以及polarssl,听说openssl中的加密模块特别全,并且特别好用.于是想尝试一下. 一.环境配置 下载openssl,我这里使用的是op ...
- iOS解决两个静态库的冲突 duplicate symbol
http://blog.163.com/023_dns/blog/static/118727366201391544630380/ 场景: 解决TencentOpenAPI.framework与Zba ...
- 【原】IOS合并lib(.a)库的终极可用方法(可用于解决duplicate symbol静态库冲突)
网上流传了太多关于合并lib库的方法,自己也尝试过,但大多失败.有感于这种急于解决问题,经过百般尝试后依旧无果的无奈心情,小翁在这里用一个实例来完整阐述如何在mac中合并lib静态库. 这里以移动广告 ...
随机推荐
- IIS 部署nodejs
1.Node.js 2.IIS的URL Rewrite模块 3.iisnode
- SpringBoot项目在IntelliJ IDEA中实现热部署(简单方式)
------ 开启idea自动make/build功能 ----- 1.CTRL + SHIFT + A --> 查找make project automatically --> ...
- windows关闭aslr办法
关闭aslr方便调试分析. 转:https://www.52pojie.cn/thread-377450-1-1.html windows关闭aslr办法 如 @Hmily 前辈所说, Window ...
- XML和HTML的区别
1.很多新手程序员总是会问HTML和XML有什么区别,接下来就解释一下: 什么是XML? XML 指可扩展标记语言(EXtensible Markup Language). XML 是一种很像HTML ...
- powershell 获取 CPU 物理 / 逻辑核心数
转载请注明: 仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/ 获取 CPU 逻辑核心数的方法为:总逻辑核心数 = 物理核心数 * 每核逻辑核心数 其中 ...
- UVA12995 Farey Sequence [欧拉函数,欧拉筛]
洛谷传送门 Farey Sequence (格式太难调,题面就不放了) 分析: 实际上求分数个数就是个幌子,观察可以得到,所求的就是$\sum^n_{i=2}\phi (i)$,所以直接欧拉筛+前缀和 ...
- shell中的条件判断if和测试
(一)条件判断 if 中-z 到 -d 的意思 [ -a file ] 若file存在,则为真. [ -b file ] 若file存在且是一个块特殊文件,则为真. [ -c file ] 若file ...
- java 接口 继承 接口 抽象类 继承 实体类
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha 接口 可以 继承 接口 抽象类 可以 实现 接口 抽象类 继承实体类 需要 实体类 有 ...
- CodeForces 1063C. Dwarves, Hats and Extrasensory Abilities 交互
题目大意: 依次给定$n$个点的颜色,要求给定这$n$个点的坐标以及一条可以把他们分成两部分的直线 强制在线(交互) $n \leqslant 30$ 感觉自己真像一个乱搞... 我们只考虑把点放在最 ...
- luoguP3830 [SHOI2012]随机树 期望概率 + 动态规划 + 结论
题意非常的复杂,考虑转化一下: 每次选择一个叶节点,删除本叶节点(深度为$dep$)的同时,加入两个深度为$dep + 1$的叶节点,重复$n$轮 首先考虑第$1$问,(你看我这种人相信数据绝对是最大 ...