title: Undefined reference to RSA_generate_key in OpenSSL?
body: <p>I have the following code in the file <code>rsatest.c</code>. I'm trying to generate a RSA key pair.</p>
  
  <pre><code>#include &lt;openssl/rsa.h&gt;
  #include &lt;openssl/pem.h&gt;
  
  int main(){
      RSA *rsa = RSA_generate_key((const int) 1024,(const int) 3, 0, 0);
      return 0;
  }
  </code></pre>
  
  <p>I'm compiling this with</p>
  
  <pre><code>gcc -I../include/ -L . -lcrypto -lssl rsatest.c
  </code></pre>
  
  <p>and I get the following error.</p>
  
  <pre><code> undefined reference to `RSA_generate_key'
  </code></pre>
  
  <p>Am I linking the library files in the wrong order? I made the libcrypto.a and libssl.a on windows (64 bit), with msys and mingw, and I'm running the code on the same system.</p>
  
  <p>RSA_generate_key has been declared in rsa.h. Is it not defined in libcrypto.a?</p>
  
  <p>EDIT :</p>
  
  <p>I tried this too,</p>
  
  <pre><code>gcc -I../include rsatest.c -L . -lcrypto -lssl
  </code></pre>
  
  <p>and I understand that the linker will look for definitions in the libraries going from left to right.</p>
  
  <p>However, I get new undefined references to various functions in </p>
  
  <pre><code>rand_win.o and c_zlib.o
  </code></pre>
  
  <p>I looked up online and found the missing symbols in the libraries gdi32 and zlib. So I added </p>
  
  <pre><code>-lz and -lgdi32
  </code></pre>
  
  <p>The compiler did not complain about a missing library, so I assume they are present with mingw. And still, I get the same output.</p>
  
  <p>I also used nm, and found that the symbols were indeed undefined in rand_win.o and c_zlib.o.</p>
  
  <p>Why cant the linker seem to find definitions in these libraries?</p>