openssl:undefined reference to symbol ‘EVP_EncryptUpdate@@libcrypto.so.10’

查看 openssl 版本:

$ openssl version -a
OpenSSL 1.0.2k-fips  26 Jan 2017
built on: reproducible build, date unspecified
platform: linux-x86_64
options:  bn(64,64) md2(int) rc4(16x,int) des(idx,cisc,16,int) idea(int) blowfish(idx)
compiler: gcc -I. -I.. -I../include  -fPIC -DOPENSSL_PIC -DZLIB -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DKRB5_MIT -m64 -DL_ENDIAN -Wall -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic -Wa,--noexecstack -DPURIFY -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DRC4_ASM -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM
OPENSSLDIR: "/etc/pki/tls"
engines:  rdrand dynamic

Code:

$ cat main.c
#include <stdio.h>
#include <stdlib.h>
#include <openssl/evp.h>
#include <openssl/x509.h>void encrypt_des_ede_cbc_pkcs(unsigned char *in,     // 待加密数据unsigned int   inLen,   // 待加密数据字节数unsigned char *key,      // 密  钥,长度总是24字节unsigned char *iv)       // 偏移量,长度总是08字节
{printf("encrypt......\n\n");unsigned char *outBuf;unsigned int outBufLen, outLen1, outLen2;/* 依据PKCS填充规则 */outBufLen = (inLen/8 + 1) * 8;outBuf = (unsigned char *)malloc(outBufLen);EVP_CIPHER_CTX ctx;EVP_CIPHER_CTX_init(&ctx);EVP_EncryptInit_ex(&ctx, EVP_des_ede3_cbc(), NULL, key, iv);EVP_EncryptUpdate(&ctx, outBuf, &outLen1, in, inLen);EVP_EncryptFinal_ex(&ctx, outBuf+outLen1, &outLen2);unsigned int i;for (i = 0; i < outBufLen; i++){printf("%02x ", outBuf[i]);}printf("\n");free(outBuf);printf("in: %p\n", in);printf("inLen: %u\n", inLen);printf("outBufLen: %u\n", outBufLen);printf("outLen1: %u\n", outLen1);printf("outLen2: %u\n", outLen2);printf("\n\n");
}void decrypt_des_ede_cbc_pkcs(unsigned char *out,      // 待解密数据unsigned int   outLen,  // 待解密数据字节数unsigned char *key,      // 密  钥,长度总是24字节unsigned char *iv)       // 偏移量,长度总是08字节
{printf("decrypt......\n\n");unsigned char *inBuf;unsigned int inBufLen, inLen1, inLen2;/* 依据PKCS填充规则 */inBufLen = (outLen/8 - 1) * 8;inBuf = (unsigned char *)malloc(inBufLen);EVP_CIPHER_CTX ctx;EVP_CIPHER_CTX_init(&ctx);EVP_DecryptInit_ex(&ctx, EVP_des_ede3_cbc(), NULL, key, iv);EVP_DecryptUpdate(&ctx, inBuf, &inLen1, out, outLen);EVP_DecryptFinal_ex(&ctx, inBuf+inLen1, &inLen2);unsigned int i;for (i = 0; i < inBufLen; i++){printf("%02x ", inBuf[i]);}printf("\n");free(inBuf);printf("out: %p\n", out);printf("outLen: %u\n", outLen);printf("inBufLen: %u\n", inBufLen);printf("inLen1: %u\n", inLen1);printf("inLen2: %u\n", inLen2);printf("\n\n");
}int main()
{/* 加载算法 */OpenSSL_add_all_algorithms();/* 密钥长度24字节 */unsigned char key[]   = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef };/* 偏移量长度8字节 */unsigned char iv []   = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef };/* 加密 */unsigned char in [] = "test1280";unsigned int  inLen = 8; // 不可strlen(in),考虑到in中包含0x00字节会导致获取待加密数据长度错误encrypt_des_ede_cbc_pkcs(in, inLen, key, iv);/* 解密 */unsigned char out[] = {    0x64, 0x5a, 0x6b, 0xd6, 0xbf, 0xf8, 0x36, 0xb2,0x4f, 0xd1, 0x74, 0xf6, 0xe7, 0xf6, 0xaf, 0xdb };unsigned int outLen = 16;// 不可strlen(out)decrypt_des_ede_cbc_pkcs(out, outLen, key, iv);return 0;
}

编译:gcc -o main main.c -lssl

$ gcc -o main main.c -lssl
/bin/ld: /tmp/ccMSnaP0.o: undefined reference to symbol 'EVP_EncryptUpdate@@libcrypto.so.10'
/bin/ld: note: 'EVP_EncryptUpdate@@libcrypto.so.10' is defined in DSO /lib64/libcrypto.so.10 so try adding it to the linker command line
/lib64/libcrypto.so.10: could not read symbols: 无效的操作
collect2: 错误:ld 返回 1

即:
undefined reference to symbol ‘EVP_EncryptUpdate@@libcrypto.so.10’

解决办法:

gcc -o main main.c -lssl -lcrypto

重点是添加 -lcrypto 这个动态链接库。

参考:
1.http://blog.sina.com.cn/s/blog_45497dfa0100nxi3.html
2.https://blog.csdn.net/u010587433/article/details/51211383
3.https://blog.51cto.com/chaoyuezhangsan/1745230
4.https://stackoverflow.com/questions/17812344/undefined-reference-to-symbol-bio-ctrllibcrypto-so-10

I think is missing -lcrypto on the command that you put

openssl:undefined reference to symbol 'EVP_EncryptUpdate@@libcrypto.so.10'相关推荐

  1. linux下gcc编译使用opencv的源文件时报错的处理:undefined reference to symbol '_ZNSsD1Ev@@GLIBCXX_3.4'

    这阵子用OpenCV的sift做了一下匹配,在使用gcc编译时遇到这样的一个报错 /usr/bin/ld: /tmp/cceCEx1F.o: undefined reference to symbol ...

  2. SLAM 14讲中cere拟合曲线代码报错:undefined reference to symbol ‘omp_get_num_threads@@OMP_1.0‘

    视觉SLAM 14讲中cere拟合曲线代码报错: /usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libceres.a(coordinate_descent_ ...

  3. 【Makefile】报错:undefined reference to symbol ‘pthread_spin_init@@GLIBC_2.2.5‘

    详细报错截图: gcc -std=gnu99 -Wall -O0 -g -o /home/book/SVN/LM20007/automatic_test/bin/autoTest /home/book ...

  4. undefined reference to symbol ‘_ZN2cv7imwriteERKNS_6StringERKNS_11_InputArrayERKSt6vectorIiSaIiEE‘

    ubuntu系统,先装了opencv2.4.9,后来又安装了opencv3.0,qt下编译项目报错: :-1: error: tracker_run.o: undefined reference to ...

  5. opencv undefined reference to symbol '_ZN2c...异常

    异常: /usr/bin/ld: ./src/flann.o: undefined reference to symbol '_ZN2cv5flann12SearchParamsC1Eifb' 解决: ...

  6. gentoo rt-thread scons --menuconfig libs/lxdialog/util.o: undefined reference to symbol 'nodelay'

    gentoo rt-thread scons --menuconfig libs/lxdialog/util.o: undefined reference to symbol 'nodelay' 今天 ...

  7. SLAM十四讲ch7代码调整(undefined reference to symbol)

    SLAM十四讲ch7代码调整--2021.6.14 1.首先大部分的代码需要在Cmakelists中更新至c++14,否则会出现如下报错 /usr/local/include/g2o/core/bas ...

  8. gcc编译报错:undefined reference to `std::cout‘

    1 问题描述 下面的一段代码(代码来源)在使用gcc编译的时候报错:undefined reference tostd::cout'` 编译文件:test.cpp内容如下: #include < ...

  9. Linux系统下GCC编译错误:“undefined reference to ‘sqrt‘”

    Linux系统下GCC编译错误:"undefined reference to 'sqrt'",解决方法:-lm 数学函数sqrt()位于libm.so库文件中(这些库文件通常位于 ...

最新文章

  1. java制表位是什么意思_java制表位如何应用?大神进来。
  2. SAP SD 关于信用管理--信用更新
  3. Android.mk中添加宏定义
  4. 小程序功能模块-在线考试2.10.3源码
  5. (24)System Verilog设计十进制计数器
  6. ps aux 查看进程信息
  7. wifi上行下行速度测试_测试网速_测试网速wifi在线测试
  8. Excel用公式计算年龄
  9. Js求时间差、并转换为字符串
  10. html坦克游戏,HTML5+JS实现坦克大战小游戏
  11. VBA快速转换数据格式,将CBOT结算价历史数据导入数据库(图文)
  12. 京东背调一星期,范围广到可怕。网友:这特么比入党还难?
  13. visca协议c语言,VISCA协议控制键盘 SONY VISCA协议会议摄像机控制键盘NK-EVI603K
  14. 如何批量修改图片名称?
  15. 华为matepad切换电脑模式_华为matepadpro可以当电脑用吗,华为matepad pro怎么切换电脑模式...
  16. 基于python的微信好友数据分析_python 微信好友特征数据分析及可视化
  17. 获取linux系统序列号
  18. 机器学习算法(九): 基于线性判别LDA模型的分类(基于LDA手写数字分类实践)
  19. 怎样确定期刊是否是SCI检索期刊或者EI检索期刊以及SCI分区
  20. 微信小程序-豆瓣电影

热门文章

  1. C++下OPENCV驱动调用海康GigE工业相机
  2. 『金融帝国实验室』(CapLab)〔官方正版游戏程式/补丁〕更新发布_V8.1.03(2022年第27次)
  3. DM_SQL索引相关
  4. 手游服务器ip 修改密码,手机挂常用ip改QQ密码技巧
  5. 智能电表MCU需求,及电表芯片厂商排名
  6. idea将指定目录打成jar包
  7. comps.xml文件定制
  8. 计算机技术为什么更新快,为什么电脑更新换代的速度那么快?
  9. 聚苏丹红Ⅲ膜/磺化聚醚醚酮膜/ SiO2/Ag纤维复合材料修饰多巴胺的研究
  10. jmeter并发误区及集合点(同步计时器),吞吐量定时器