3

I got the following compile error even though I added the include path to openssl. I'm using vscode on a MAC. Can you tell me how to fix it?

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

I found the similar issue but still did not find the solution for me yet.

Compiling C programs using libssl on OS X El Capitan?

How to use OpenSSL with GCC?

http://qiita.com/marumaru/items/ca801c957986302f6fe6


Update 2

I tried to compile using g++ but it did not work too. My mac is 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.

Update 3

Problem solved. I added -I and -L options.

g++ main.cpp -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib -lssl -lcrypto -o test

1 Answer 1

1

Another solution: On Mac (but this should work on other OSs as well), I first updated openssl:

brew upgrade openssl

Then setup the following env variables:

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

Which I got by simply trying:

brew info openssl

I still had to update tasks.json, but now the changes worked (clang for 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"
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.