2

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.

Community
  • 1
  • 1
Sashank
  • 107
  • 2
  • 11
  • Maybe your want read [this](https://wiki.openssl.org/index.php/Compilation_and_Installation). GL ♥ HF. And generally we prefer use dynamic library to save RAM space. That why by default openssl don't link with zlib or gdi32lib statically. – Stargateur Nov 17 '16 at 13:43
  • _aren't static libcrypto and libssl self sufficient?_ You should add `-static` to compile with static libs. – LPs Nov 17 '16 at 13:49
  • These may help: [Why does order in which input libraries are specified matter?](http://stackoverflow.com/q/8367888), [Why does the library linker flag sometimes have to go at the end using GCC?](http://stackoverflow.com/q/9417169), [How to use OpenSSL in GCC?](http://stackoverflow.com/q/1894013) – jww Nov 17 '16 at 14:43

0 Answers0