2

I have this C++ code which does not compile on OS X:

#include <iostream>
#include <openssl/evp.h>

int main(int argc,char *argv[]){
        EVP_PKEY_CTX *pctx;
        pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL);
        return 0;
}

At link I get this error:

Undefined symbols for architecture x86_64:
  "_EVP_PKEY_CTX_new_id", referenced from:
      _main in test-a22ea1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

compiled with:

g++ test.cpp -o test -lssl -lcrypto

OpenSSl doc, says that it should be defined: https://www.openssl.org/docs/manmaster/crypto/EVP_PKEY_CTX_new.html

This code works perfectly on a Linux (Debian 7 with OpenSSL 1.0.1e). But not on OS X. Any suggestion?

My config:

  • OS X: 10.11.2
  • clang: Apple LLVM version 7.0.2 (clang-700.1.81)
  • openSSL: OpenSSL 1.0.2e 3 Dec 2015 (installed with Homebrew)

Thank and happy new year :)

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
Ricain
  • 638
  • 1
  • 4
  • 17
  • C is not C++ is not C! – too honest for this site Dec 31 '15 at 18:49
  • Possible duplicate of [Compiling and linking OpenSSL on Ubuntu vs OSX](http://stackoverflow.com/q/14150772). – jww Jan 01 '16 at 03:39
  • 1
    If you want to see examples of actually using some C++ features with OpenSSL, then take a look at [How to generate RSA private key using openssl](http://stackoverflow.com/a/30493975/608639) and [Using openssl to generate a DSA key pair](http://stackoverflow.com/a/22580463/608639). The answers use `unique_ptr` to automatically free resources acquired with OpenSSL's `*_new` functions, like `RSA_new` and `DSA_new`. – jww Jan 01 '16 at 03:45

1 Answers1

2

Is the linker perhaps picking up another version of ssl and crypto library files that were already installed on the system? Try adding the -L switch with the path to the homebrew-installed files.

screwnut
  • 1,367
  • 7
  • 26