【发布时间】:2019-11-15 17:48:04
【问题描述】:
即使我将包含路径添加到 openssl,我也收到以下编译错误。我在 MAC 上使用 vscode。能告诉我怎么解决吗?
错误
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
更新 1
我发现了类似的问题,但仍然没有找到适合我的解决方案。
Compiling C programs using libssl on OS X El Capitan?
http://qiita.com/marumaru/items/ca801c957986302f6fe6
更新 2
我尝试使用 g++ 进行编译,但也没有成功。我的mac是OS X El Capitan version10.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.
更新 3
问题解决了。我添加了 -I 和 -L 选项。
g++ main.cpp -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib -lssl -lcrypto -o test
【问题讨论】: