I'm trying to use the OpenSSL EVP.h
in a C++ file. Each time I try to compile, however, I get an error about linking, for example:
ld: can't map file, errno=22 file '/usr/local/opt/openssl@3/lib/' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1
I've tried the following solutions:
- Linker and compiler errors with openssl
- I’ve tried reinstalling with openssl with brew
- Tried both:
- -I/usr/local/opt/openssl@1.1/include
- -I/usr/local/opt/openssl@3/include
- Tried adding on “-libssl -libcrypto” on the end, only for it to say “ld: library not found for -libssl”
- Doing
ls /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/ | grep “ssl”
returns only libboringssl.tbd - Doing
find /usr/local/opt/openssl@3/ | grep “libssl”
returns /lib/libssl.a among other files - If I attach “-arch x86_64” to my compile command, it says:
ld: can't map file, errno=22 file '/usr/local/opt/openssl@3/lib/' for architecture x86_64
My code is:
#include <stdio.h>
#include <iostream>
#include <openssl/evp.h>
using namespace std;
int main(){
#define kek 20
#define key_len 32
#define iteration 1
unsigned char salt[] = {'s', 'a', 'l', 't'};
char password[] = "test";
unsigned char *out;
size_t i;
out = (unsigned char *) malloc(sizeof(unsigned char) * kek);
if( PKCS5_PBKDF2_HMAC_SHA1(password, strlen(password), salt, sizeof(salt), iteration, kek, out) != 0 )
{
cout << out;
}
free(out);
return 0;
}
The command I'm using to compile is: g++ -I/usr/local/opt/openssl\@3/include -Wl,/usr/local/opt/openssl\@3/lib/ -arch x86_64 test.cpp
My macOS version is Big Sur 11.2.