0

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.

Aamir
  • 1,974
  • 1
  • 14
  • 18
GhostDog98
  • 61
  • 5
  • You are providing the wrong arguments to `g++`. Instead of the `-Wl` option, you should provide a `-L` option with the `/usr/local/opt/openssl\@3/lib/` directory path as argument and afterwards you should add `-l` options _after_ `test.cpp` matching the library you want to link without the `lib` prefix and `.a`/`.so` suffix, e.g. `-lssl -lcrypto`. – user17732522 Jun 17 '22 at 04:16
  • Ah! Thank you so much. For future peoples, this is the command that ended up working for me: `g++ -I/usr/local/opt/openssl\@3/include -arch x86_64 -L/usr/local/opt/openssl\@3/lib/ test.cpp -lssl -lcrypto`. Would you like to add that as an answer so I can mark it as correct @user17732522 ? – GhostDog98 Jun 17 '22 at 04:24

0 Answers0