14

In Ubuntu 11.10 x86_64 I have this this simple test.c file:

#include <openssl/ssl.h>

int main() {
    SSL_library_init();
    return 0;
}

Why does compiling with gcc fail?

$ gcc -lssl -lcrypto test.c
/tmp/ccqL6lRY.o: In function `main':
test.c:(.text+0x5): undefined reference to `SSL_library_init'
collect2: ld returned 1 exit status

Compiling with clang works and produces a working executable:

$ clang -lssl -lcrypto test.c
$ ldd a.out 
linux-vdso.so.1 =>  (0x00007fffa93e1000)
libssl.so.1.0.0 => /lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f234a24f000)
libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f2349ea0000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2349b00000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f23498fc000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f23496e4000)
/lib64/ld-linux-x86-64.so.2 (0x00007f234a4c4000
fornwall
  • 2,877
  • 3
  • 25
  • 38

2 Answers2

29

Try to put -lssl at the end (after test.c).

$ gcc test.c -lssl -lcrypto
cnicutar
  • 178,505
  • 25
  • 365
  • 392
0

Add below in your make file "in the same order": "LDFLAGS += -lssl -lcrypto"

See more details here: Undefined reference to SSL_library_init and SSL_load_error_strings

  • There are other answers that provide the OP's question, and they were posted some time ago. When posting an answer [see: How do I write a good answer?](https://stackoverflow.com/help/how-to-answer), please make sure you add either a new solution, or a substantially better explanation, especially when answering older questions. – help-info.de Nov 03 '19 at 17:32