I'm attempting to use OpenSSL's EVP interface to do some encryption. I'm pretty sure my code is right, but I can't seem to get it to compile. I'm using GCC, and Ubuntu 32-bit precise with libssl-dev installed and at the latest version.
The project currently consists of one file,
i = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha1() ... );
gcc -Wall -g -lssl -lcrypto -o program program.c
/home/andy/program/program.c:31: undefined reference to `EVP_sha1'
/home/andy/program/program.c:31: undefined reference to `EVP_aes_256_cbc'
/home/andy/program/program.c:31: undefined reference to `EVP_BytesToKey'
/home/andy/program/program.c:44: undefined reference to `EVP_CIPHER_CTX_init'
andy@ProgStation2:/usr/include$ find . | grep evp.h
It turns out it was something stupid. In the linker step, I was using
gcc -Wall -g -lssl -lcrypto -o program program.o. I needed to move the library links to after the object file I was linking, and put
gcc -Wall -g -o program program.o -lssl -lcrypto