【问题标题】:'openssl/crypto.h' file not found on vscode在 vscode 上找不到“openssl/crypto.h”文件
【发布时间】: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.

ma​​in.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?

How to use OpenSSL with GCC?

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

【问题讨论】:

    标签: c++ visual-studio-code


    【解决方案1】:

    另一种解决方案: 在 Mac 上(但这也应该适用于其他操作系统),我首先更新了 openssl:

    brew upgrade openssl
    

    然后设置以下环境变量:

    export LDFLAGS="-L/usr/local/opt/openssl/lib"
    export CPPFLAGS="-I/usr/local/opt/openssl/include"
    

    我通过简单的尝试得到了:

    brew info openssl
    

    我仍然需要更新 tasks.json,但现在更改有效(clang 为 c):

    {
        "tasks": [
            {
                "type": "shell",
                "label": "clang build active file",
                "command": "/usr/bin/clang",
                "args": [
                    "-g",
                    "${file}",
                    "-o",
                    "${fileDirname}/${fileBasenameNoExtension}",
                    "-I/usr/local/opt/openssl/include",
                    "-L/usr/local/opt/openssl/lib",
                    "-lssl",
                    "-lcrypto"
                ],
                "options": {
                    "cwd": "/usr/bin"
                }
            }
        ],
        "version": "2.0.0"
    }
    

    【讨论】:

      猜你喜欢
      • 2018-01-23
      • 1970-01-01
      • 2019-07-18
      • 2018-05-14
      • 2020-10-17
      • 2017-09-25
      • 2017-06-22
      • 2017-12-07
      • 2022-07-18
      相关资源
      最近更新 更多