即使我将包含路径添加到 openssl,我也收到以下编译错误。我在 MAC 上使用 vscode。你能告诉我如何修复它吗?
Error
main.cpp:3:10: fatal error: 'openssl/crypto.h' file not found
#include <openssl/crypto.h>
^
1 error generated.
main.cpp
#include <iostream>
#include <openssl/crypto.h>
using namespace std;
int main()
{
cout << "hoge" << endl;
}
.vscode/tasks.json
{
"version": "0.1.0",
"command": "g++",
"isShellCommand": true,
"args": ["-std=c++14", "-O2", "-l", "boost_system", "-l", "boost_thread", "-o", "test", "-g",
"main.cpp"
],
"showOutput": "always"
}
.vscode/c_cpp_properties.json
{
"configurations": [
{
"name": "Mac",
"includePath": [
"/usr/include",
"/usr/local/include",
"/usr/local/opt/openssl/include"
],
"browse": {
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": "",
"path": [
"/usr/include",
"/usr/local/include",
"/usr/local/opt/openssl/include"
]
}
}
]
}
.vscode/c_cpp_properties.json
$ which openssl
/usr/bin/openssl
$ ls /usr/local/opt/openssl/include/openssl | grep crypto.h
crypto.h
Update 1
我发现了类似的问题,但仍然没有找到适合我的解决方案。
在 OS X El Capitan 上使用 libssl 编译 C 程序? https://stackoverflow.com/questions/33530865/compiling-c-programs-using-libssl-on-os-x-el-capitan
如何将 OpenSSL 与 GCC 一起使用? https://stackoverflow.com/questions/1894013/how-to-use-openssl-in-gcc
http://qiita.com/marumaru/items/ca801c957986302f6fe6 http://qiita.com/marumaru/items/ca801c957986302f6fe6
Update 2
我尝试使用 g++ 进行编译,但它也不起作用。我的 Mac 是 OS X El Capitan 版本10.11.6
$ g++ main.cpp -L/usr/local/opt/openssl/lib -lssl -lcrypto -o test
main.cpp:3:10: fatal error: 'openssl/crypto.h' file not found
#include <openssl/crypto.h>
^
1 error generated.
Update 3
问题解决了。我添加了 -I 和 -L 选项。
g++ main.cpp -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib -lssl -lcrypto -o test