4

I am trying to compile a C program which depends on some SSL libraries. When I try to compile I get the following error:

michael@michael-VirtualBox:~/$ cc -lssl -lcrypto iot.o tun2iot.o -o tun2iot
iot.o: In function `_iot_wfd_new':
iot.c:(.text+0x21b): undefined reference to `CRYPTO_malloc'
iot.o: In function `_iot_wfd_free':
iot.c:(.text+0x289): undefined reference to `CRYPTO_free'
iot.c:(.text+0x29d): undefined reference to `CRYPTO_free'
iot.o: In function `_iot_frame_ind':
iot.c:(.text+0x366): undefined reference to `CRYPTO_free'
iot.o: In function `_iot_error_ind':
iot.c:(.text+0x3f4): undefined reference to `CRYPTO_free'
iot.o: In function `_iot_do_phase_connect':
iot.c:(.text+0xb95): undefined reference to `SSL_connect'
iot.c:(.text+0xbad): undefined reference to `SSL_get_error'
iot.o: In function `_iot_frame_recv':
iot.c:(.text+0xfe6): undefined reference to `CRYPTO_free'
iot.c:(.text+0x1377): undefined reference to `CRYPTO_free'
iot.o: In function `_iot_do_read':
iot.c:(.text+0x1443): undefined reference to `SSL_read'
iot.c:(.text+0x1458): undefined reference to `SSL_get_error'
iot.c:(.text+0x1489): undefined reference to `SSL_pending'
iot.c:(.text+0x150e): undefined reference to `SSL_read'
iot.c:(.text+0x1564): undefined reference to `CRYPTO_malloc'
iot.c:(.text+0x1595): undefined reference to `SSL_read'
iot.c:(.text+0x15d2): undefined reference to `SSL_read'
iot.c:(.text+0x15e0): undefined reference to `SSL_pending'
iot.c:(.text+0x1640): undefined reference to `BIO_test_flags'
iot.c:(.text+0x165a): undefined reference to `BIO_test_flags'
iot.o: In function `_iot_do_write':
...

When I add the following arguments to the compiler I get a different error:

michael@michael-VirtualBox:~/$ cc -lssl -lcrypto iot.o tun2iot.o -o tun2iot /usr/lib/i386-linux-gnu/libcrypto.a /usr/lib/i386-linux-gnu/libssl.a 
/usr/lib/i386-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
(.text+0x1d): undefined reference to `dlopen'
/usr/lib/i386-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
(.text+0x33): undefined reference to `dlsym'
/usr/lib/i386-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
(.text+0x3d): undefined reference to `dlclose'
/usr/lib/i386-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
(.text+0x3b1): undefined reference to `dlsym'
/usr/lib/i386-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
(.text+0x490): undefined reference to `dlerror'
/usr/lib/i386-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
(.text+0x511): undefined reference to `dlsym'
/usr/lib/i386-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
(.text+0x5f0): undefined reference to `dlerror'
/usr/lib/i386-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
(.text+0x667): undefined reference to `dlopen'
/usr/lib/i386-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
(.text+0x6de): undefined reference to `dlclose'
/usr/lib/i386-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
(.text+0x715): undefined reference to `dlerror'
/usr/lib/i386-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr':
(.text+0x7b1): undefined reference to `dladdr'
/usr/lib/i386-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr':
(.text+0x819): undefined reference to `dlerror'
/usr/lib/i386-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
(.text+0x87a): undefined reference to `dlclose'
/usr/lib/i386-linux-gnu/libcrypto.a(c_zlib.o): In function `bio_zlib_free':
(.text+0x4f): undefined reference to `inflateEnd'
/usr/lib/i386-linux-gnu/libcrypto.a(c_zlib.o): In function `bio_zlib_free':
(.text+0x6b): undefined reference to `deflateEnd'
/usr/lib/i386-linux-gnu/libcrypto.a(c_zlib.o): In function `bio_zlib_ctrl':
(.text+0x252): undefined reference to `deflate'
/usr/lib/i386-linux-gnu/libcrypto.a(c_zlib.o): In function `bio_zlib_ctrl':
...

Does anybody have any ideas??

TomSelleck
  • 6,706
  • 22
  • 82
  • 151
  • 4
    Link your libraries *after* your object code files. I.e. put them *last* on your link line. `cc -o tun2iot iot.o tun2iot.o -lssl -lcrypto` – WhozCraig Sep 02 '13 at 10:53
  • Ah thank you very much! You should post this as an answer! – TomSelleck Sep 02 '13 at 11:07
  • 1
    It already is somewhere out there in SO. I'm too lazy to hunt down the dupe, but I know its out there. I might try later. Too late here. Need sleep. Anyway, glad you're up and running. – WhozCraig Sep 02 '13 at 11:13

1 Answers1

5

cc -lssl -lcrypto iot.o tun2iot.o -o tun2iot

This command line is incorrect. See e.g. this for an explanation.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362