0

I am currently working on a project on encryption and decryption using OpenSSL library, and I'm trying to run a simple encryption. This is my make file:

INC=/usr/local/ssl/include/
LIB=/usr/local/ssl/lib/

all:
        gcc -I$(INC) -L$(LIB) -o out encryption.c -lcrypto -ldl

Must note I'm not using Xcode or anything like it, just the Terminal. And these are the errors I am receiving:

gcc -I/usr/local/ssl/include/ -L/usr/local/ssl/lib/ -o out ex_1.c -lcrypto -ldl
ld: warning: ignoring file /usr/local/ssl/lib//libcrypto.a, file was built for archive which is not the architecture being linked (x86_64): /usr/local/ssl/lib//libcrypto.a
Undefined symbols for architecture x86_64:
  "_BIO_dump_fp", referenced from:
      _main in ex_1-a0d79f.o
  "_ERR_free_strings", referenced from:
      _main in ex_1-a0d79f.o
  "_ERR_load_crypto_strings", referenced from:
      _main in ex_1-a0d79f.o
  "_ERR_print_errors_fp", referenced from:
      _handleErrors in ex_1-a0d79f.o
  "_EVP_CIPHER_CTX_free", referenced from:
      _encrypt in ex_1-a0d79f.o
      _decrypt in ex_1-a0d79f.o
  "_EVP_CIPHER_CTX_new", referenced from:
      _encrypt in ex_1-a0d79f.o
      _decrypt in ex_1-a0d79f.o
  "_EVP_DecryptFinal_ex", referenced from:
      _decrypt in ex_1-a0d79f.o
  "_EVP_DecryptInit_ex", referenced from:
      _decrypt in ex_1-a0d79f.o
  "_EVP_DecryptUpdate", referenced from:
      _decrypt in ex_1-a0d79f.o
  "_EVP_EncryptFinal_ex", referenced from:
      _encrypt in ex_1-a0d79f.o
  "_EVP_EncryptInit_ex", referenced from:
      _encrypt in ex_1-a0d79f.o
  "_EVP_EncryptUpdate", referenced from:
      _encrypt in ex_1-a0d79f.o
  "_EVP_aes_256_cbc", referenced from:
      _encrypt in ex_1-a0d79f.o
      _decrypt in ex_1-a0d79f.o
  "_EVP_cleanup", referenced from:
      _main in ex_1-a0d79f.o
  "_OPENSSL_add_all_algorithms_noconf", referenced from:
      _main in ex_1-a0d79f.o
  "_OPENSSL_config", referenced from:
      _main in ex_1-a0d79f.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1

It works just fine on Ubuntu, on a VirtualBox, while I'm trying to make this work on OS X. I've seen many topics on this but they don't seem to help because they're linked with an IDE or so.

  • What version of OS X? – dbush Dec 12 '16 at 19:38
  • I am using 10.11.6 – Ilinca Roman Dec 12 '16 at 19:41
  • What does `file /usr/local/ssl/lib/libcrypto.a` tell you? – twalberg Dec 12 '16 at 19:52
  • `/usr/local/ssl/lib/libcrypto.a: current ar archive random library` – Ilinca Roman Dec 12 '16 at 20:24
  • 2
    It looks like your `libcrypto.a` is built for 32-bit compilations and not 64-bit compilations. You can use `cd /tmp; ar t /usr/local/ssl/lib/libcrypto.a; ar x /usr/local/ssl/lib/libcrypto.a objectfile.o; file objectfile.o` where `objectfile.o` is any of the object files listed in the archive. The output from `file` should tell you whether it is compiled for 32-bit or 64-bit or both. – Jonathan Leffler Dec 12 '16 at 21:08
  • `lipo -info libcrpto.a` will tell you if its 32-bit, 64-bit or a fat library. Also see [Compilation and Installation](https://wiki.openssl.org/index.php/Compilation_and_Installation) on the OpenSSL wiki and [Build Multiarch OpenSSL on OS X](http://stackoverflow.com/q/25530429) on Stack Overflow. – jww Dec 13 '16 at 12:43
  • For a quick/dirty test of architectures, try changing your make recipe to include `CFLAGS` of `-arch i386`. If it compiles and links, then `libcrypto.a` is 32-bit. GCC on Darwin [accepts `-arch` option](https://gcc.gnu.org/onlinedocs/gcc/Darwin-Options.html) (but you are probably using Clang). – jww Dec 13 '16 at 12:47
  • Please check using nm or strings on the library file if the symbols are present or not. Also, check compatibility. Libraries in OS X are generally compiled using clang. May be some other mismatch. – doptimusprime Dec 14 '16 at 07:30

0 Answers0