Reputation: 11
I am new about coding and I have this problem: I need to compile a C program that uses openMP and openSSL. I installed openSSL using Homebrew getting this:
If you build your own software and it requires this formula, you'll need to add to your build variables:
LDFLAGS: -L/usr/local/opt/openssl/lib CPPFLAGS: -I/usr/local/opt/openssl/include
and then I used the following command
gcc-4.9 -std=c99 -fopenmp main.c -L/usr/local/opt/openssl/lib -lssl
and I get the following errors
Undefined symbols for architecture x86_64: "_CRYPTO_free", referenced from:
_openmp_thread_cleanup in ccESSonD.o "_CRYPTO_malloc", referenced from:
_openmp_thread_setup in ccESSonD.o "_CRYPTO_num_locks", referenced from:
_openmp_thread_setup in ccESSonD.o
_openmp_thread_cleanup in ccESSonD.o "_CRYPTO_set_id_callback", referenced from:
_openmp_thread_setup in ccESSonD.o
_openmp_thread_cleanup in ccESSonD.o "_CRYPTO_set_locking_callback", referenced from:
_openmp_thread_setup in ccESSonD.o
_openmp_thread_cleanup in ccESSonD.o "_ERR_free_strings", referenced from:
_cleanup_EVP in ccESSonD.o "_ERR_load_crypto_strings", referenced from:
_init_EVP in ccESSonD.o "_ERR_print_errors_fp", referenced from:
_handleErrors in ccESSonD.o "_EVP_CIPHER_CTX_cleanup", referenced from:
_getAllRandomness in ccESSonD.o "_EVP_CIPHER_CTX_init", referenced from:
_setupAES in ccESSonD.o "_EVP_EncryptInit_ex", referenced from:
_setupAES in ccESSonD.o "_EVP_EncryptUpdate", referenced from:
_getAllRandomness in ccESSonD.o "_EVP_aes_128_ctr", referenced from:
_setupAES in ccESSonD.o "_EVP_cleanup", referenced from:
_cleanup_EVP in ccESSonD.o "_OPENSSL_add_all_algorithms_noconf", referenced from:
_init_EVP in ccESSonD.o "_OPENSSL_config", referenced from:
_init_EVP in ccESSonD.o "_RAND_bytes", referenced from:
_main in ccESSonD.o "_SHA256_Final", referenced from:
_H in ccESSonD.o
_H3 in ccESSonD.o "_SHA256_Init", referenced from:
_H in ccESSonD.o
_H3 in ccESSonD.o "_SHA256_Update", referenced from:
_H in ccESSonD.o
_H3 in ccESSonD.o ld: symbol(s) not found for architecture x86_64 collect2: error: ld returned 1 exit status
What is that I did wrong?????
Upvotes: 1
Views: 1894
Reputation: 102296
gcc-4.9 -std=c99 -fopenmp main.c -L/usr/local/opt/openssl/lib -lssl
CPPFLAGS
are flags to the preprocessor. You need to add -I/usr/local/opt/openssl/include
to CFLAGS
in C or CXXFLAFS
in C++. The compiler driver will pass the appropriate flags to the preprocessor.
If you omit -I/usr/local/opt/openssl/include
, then you will compile against OS X's 0.9.8 headers, but link against Homebrew's 1.0.2 libraries.
As Hanbum noted, you are also missing -lcrypto
. Order matters for the placement of libraries because the linker is single pass.
So you compile command should be:
gcc-4.9 -I/usr/local/opt/openssl/include -std=c99 -fopenmp main.c \
-L/usr/local/opt/openssl/lib -lssl -lcrypto
I need to compile a C program that uses openMP and openSSL.
Related (and your mileage may vary)... OpenMP is a easy way to get portable threads. However, benchmarks against Crypto++ (which has OpenMP support) showed they slowed things down, rather than speeding things up.
Upvotes: 2