This is a follow up question to Undefined reference to RSA_generate_key in OpenSSL? I have an OpenSSL program to generate an RSA key, as follows :
#include <stdio.h>
#include <openssl/rsa.h>
#include <openssl/pem.h>
int main(int argc, char* argv[])
{
RSA *r = NULL;
int ret;
r = RSA_new();
BIGNUM *bne = NULL;
ret = RSA_generate_key_ex(r, 2048, bne, NULL);
return 0;
}
When I compile this with
gcc -I../include rsatest.c -lcrypto -L.
I get undefined reference errors to functions in libraries gdi32 and zlib.
So to correct this, I have to add -lz and -lgdi32, as
gcc -I../include/ rsatest.c -lcrypto -lz -lgdi32 -L.
My question is, aren't static libcrypto and libssl self sufficient? As in why am I having to add extra libraries to make this work? Is there an option which I should have added while compiling the library to prevent this?
I'm using a 64 bit Windows with a MinGW compiler. I made the OpenSSL library with the help of MSYS and make.