解决OpenSSL/rsa.h:没有那个文件或目录和/usr/bin/ld: cannot find -lcrypto

在编译过程中遇到OpenSSL头文件缺失及找不到-lcrypto的问题。已确认openssl安装,但/usr/include缺少openssl目录。通过查看,发现openssl目录存在。继续编译时遇到libssl.so未找到的问题。解决方案是在/usr/lib64/目录下创建libcrypto.so的软链接,指向libcrypto.so.1.0.2k或其相应版本,以解决链接错误。

编译出现OpenSSL/rsa.h:没有那个文件或目录:
但是输入:

[root@localhost ~]# openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017

已经安装openssl,但是/usr/include/目录下没有openssl目录
输入:

yum -y install openssl-devel

解决,查看之后存在openssl目录:

[root@localhost ~]# ll /usr/include/openssl/
总用量 1864
-rw-r--r--. 1 root root   6146 89 2019 aes.h
-rw-r--r--. 1 root root  63204 89 2019 asn1.h
-rw-r--r--. 1 root root  24435 89 2019 asn1_mac.h
-rw-r--r--. 1 root root  34475 89 2019 asn1t.h
-rw-r--r--. 1 root root  38742 89 2019 bio.h
-rw-r--r--. 1 root root   5351 89 2019 blowfish.h
-rw-r--r--. 1 root root  39157 89 2019 bn.h
-rw-r--r--. 1 root root   5026 89 2019 buffer.h
-rw-r--r--. 1 root root   5565 89 2019 camellia.h
-rw-r--r--. 1 root root   4659 89 2019 cast.h
-rw-r--r--. 1 root root   3257 89 2019 cmac.h
。。。。。。。。。。。。。。。。。。。。。。。。。

编译源码出现:

/usr/bin/ld: cannot find -lcrypto

原因是没有找到 libssl.so,openssl已安装
链接出错:
进入 /usr/lib64/,输入

[root@localhost lib64]# ll | grep libcrypto
lrwxrwxrwx.  1 root root       19 57 16:38 libcrypto.so -> libcrypto.so.1.0.2k
lrwxrwxrwx.  1 root root       19 57 21:52 libcrypto.so.10 -> libcrypto.so.1.0.2k
-rwxr-xr-x.  1 root root  2512448 84 2017 libcrypto.so.1.0.2k

将libcrypto.so和libcrypto.so.1.0.2k软链接起来输入:

ln -s /usr/lib64/libcrypto.so.1.0.2k /usr/lib64/libcrypto.so

不同的服务器可能libcrypto.so.1.0.2k也不同,找到对应的libcrypto.so.1.0.2k均链接成libcrypto.so就可以了。

In file included from /home/user/nvr8064/nvt98635/linux-6.12.46/certs/extract-cert.c:21:0: /usr/include/openssl/bio.h: In function 'DEPRECATEDIN_1_1_0': /usr/include/openssl/bio.h:687:1: error: expected declaration specifiers before 'DEPRECATEDIN_1_1_0' DEPRECATEDIN_1_1_0(int BIO_get_port(const char *str, unsigned short *port_ptr)) ^ /usr/include/openssl/bio.h:694:2: error: expected declaration specifiers before ';' token }; ^ In file included from /usr/include/openssl/asn1.h:23:0, from /usr/include/openssl/objects.h:15, from /usr/include/openssl/evp.h:28, from /usr/include/openssl/pem.h:16, from /home/user/nvr8064/nvt98635/linux-6.12.46/certs/extract-cert.c:22: /usr/include/openssl/bn.h:326:1: error: expected declaration specifiers before 'DEPRECATEDIN_0_9_8' DEPRECATEDIN_0_9_8(BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe, ^ /usr/include/openssl/bn.h:402:1: error: expected declaration specifiers before 'DEPRECATEDIN_0_9_8' DEPRECATEDIN_0_9_8(void BN_set_params(int mul, int high, int low, int mont)) ^ In file included from /usr/include/openssl/crypto.h:23:0, from /usr/include/openssl/bio.h:20, from /home/user/nvr8064/nvt98635/linux-6.12.46/certs/extract-cert.c:21: /usr/include/openssl/asn1.h:119:1: error: storage class specified for parameter 'sk_X509_ALGOR_compfunc' DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: storage class specified for parameter 'sk_X509_ALGOR_freefunc' DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: storage class specified for parameter 'sk_X509_ALGOR_copyfunc' DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected declaration specifiers or '...' before 'sk_X509_ALGOR_compfunc' DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected declaration specifiers or '...' before 'sk_X509_ALGOR_compfunc' DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected declaration specifiers or '...' before 'sk_X509_ALGOR_freefunc' DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected declaration specifiers or '...' before 'sk_X509_ALGOR_copyfunc' DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected declaration specifiers or '...' before 'sk_X509_ALGOR_freefunc' DEFINE_STACK_OF(X509_ALGOR) ^ /usr/include/openssl/asn1.h:119:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sk_X509_ALGOR_set_cmp_func' DEFINE_STACK_OF(X509_ALGOR) ^ In file included from /usr/include/openssl/objects.h:15:0, from /usr/include/openssl/evp.h:28, from /usr/include/openssl/pem.h:16, from /home/user/nvr8064/nvt98635/linux-6.12.46/certs/extract-cert.c:22: /usr/include/openssl/asn1.h:168:3: error: storage class specified for parameter 'ASN1_ENCODING' } ASN1_ENCODING; ^ /usr/include/openssl/asn1.h:192:3: error: storage class specified for parameter 'ASN1_STRING_TABLE' } ASN1_STRING_TABLE; ^ In file included from /usr/include/openssl/crypto.h:23:0, from /usr/include/openssl/bio.h:20, from /home/user/nvr8064/nvt98635/linux-6.12.46/certs/extract-cert.c:21: /usr/include/openssl/asn1.h:194:1: error: expected ';', ',' or ')' before '*' token DEFINE_STACK_OF(ASN1_STRING_TABLE) ^ /usr/include/openssl/asn1.h:194:1: error: expected declaration specifiers or '...' before 'ASN1_STRING_TABLE' DEFINE_STACK_OF(ASN1_STRING_TABLE) ^ /usr/include/openssl/asn1.h:194:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token DEFINE_STACK_OF(ASN1_STRING_TABLE) ^ /usr/include/openssl/asn1.h:194:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(ASN1_STRING_TABLE) ^ /usr/include/openssl/asn1.h:194:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token DEFINE_STACK_OF(ASN1_STRING_TABLE) ^ /usr/include/openssl/asn1.h:194:1: error: unknown type name 'sk_ASN1_STRING_TABLE_compfunc' DEFINE_STACK_OF(ASN1_STRING_TABLE) ^ /usr/include/openssl/asn1.h:194:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(ASN1_STRING_TABLE) ^ /usr/include/openssl/asn1.h:194:1: error: unknown type name 'sk_ASN1_STRING_TABLE_compfunc' DEFINE_STACK_OF(ASN1_STRING_TABLE) ^ /usr/include/openssl/asn1.h:194:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(ASN1_STRING_TABLE) ^ /usr/include/openssl/asn1.h:194:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(ASN1_STRING_TABLE) ^ /usr/include/openssl/asn1.h:194:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token DEFINE_STACK_OF(ASN1_STRING_TABLE) ^ /usr/include/openssl/asn1.h:194:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token DEFINE_STACK_OF(ASN1_STRING_TABLE) ^ /usr/include/openssl/asn1.h:194:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token DEFINE_STACK_OF(ASN1_STRING_TABLE) ^ /usr/include/openssl/asn1.h:194:1: error: expected declaration specifiers or '...' before 'ASN1_STRING_TABLE' DEFINE_STACK_OF(ASN1_STRING_TABLE) ^ /usr/include/openssl/asn1.h:194:1: error: expected declaration specifiers or '...' before 'ASN1_STRING_TABLE' DEFINE_STACK_OF(ASN1_STRING_TABLE) ^ /usr/include/openssl/asn1.h:194:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token DEFINE_STACK_OF(ASN1_STRING_TABLE) ^ /usr/include/openssl/asn1.h:194:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token DEFINE_STACK_OF(ASN1_STRING_TABLE) 这是什么编译问题,一大堆
最新发布
12-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值