Openssl for RSA: undefined reference to RSA_new
The propblem is that you are linking with libssl
and you are using RSA crypto which is part of libcrypto
, another error : there is no function called : RSA_new_
:
toc@UnixServer:/usr/include/openssl$ grep RSA_new *rsa.h:RSA * RSA_new(void);rsa.h:RSA * RSA_new_method(ENGINE *engine);
So correct your code:
rsa = RSA_new();
And compile like that:
gcc -I/usr/include/openssl/ -Wall my_rsa.c -o my_rsa -lcrypto
EDIT : for the last error(dl functions):
gcc -I/usr/include/openssl/ -Wall my_rsa.c -o my_rsa -lcrypto -ldl
You need to link with the library as well:
gcc -I/usr/local/ssl/include -o etc etc.c -L/usr/local/lib -lssl
The -L
option tells GCC where to look for library file, and -l
(small L) tells the linker that it should link with the library.
Replace the library folder and library name with what you got.
You have to link against the libSSL library. Something like
gcc -I /usr/local/ssl/include -o myprog myprog.c -lssl
will do the trick.
(Maybe it's not actually -lssl
but -lopenssl
, -lssl-rsa
or whatever; you can find this out by typing
pkg-config --libs PACKAGENAME
where PACKAGENAME is the name of the package which contains libssl, something like libssl, openssl, libssl-dev, openssl-devel etc.)