在Ubuntu(Linux Mint 20)上编译C++和OpenSSL

jhkqcmku  于 2023-03-01  发布在  Linux
关注(0)|答案(1)|浏览(225)

我打算在Ubuntu(Linux Mint 20.1)上使用OpenSSL编译一个小型C++项目。

  1. OpenSSL定期安装
apt-get install libssl-dev

1.编译行为

g++ -std=c++11 -o jjp jjp.cpp -ljsoncpp -lssl

1.编译器错误输出为

jjp.cpp:(.text+0xe9d): undefined reference to `ASN1_STRING_type_new'
/usr/bin/ld: json3d.cpp:(.text+0xf0d): undefined reference to `ASN1_STRING_set'
/usr/bin/ld: jjp.cpp:(.text+0xf52): undefined reference to `BIO_new_fp'
/usr/bin/ld: jjp.cpp:(.text+0xf7d): undefined reference to i2d_ASN1_OCTET_STRING'

"我做错了什么"

gzszwxb4

gzszwxb41#

要成功编译和链接OpenSSL库,编译行中必须有两个标志:

"-lssl" and "-lcrypto"

因此,正确的编译行应为:

g++ -std=c++11 -o jjp jjp.cpp -ljsoncpp -lssl -lcrypto

相关问题