【问题标题】:Compiler cannot find required SSL libraries - undefined reference to编译器找不到所需的 SSL 库 - 未定义的引用
【发布时间】:2013-09-05 10:28:10
【问题描述】:

我正在尝试编译一个依赖于某些 SSL 库的 C 程序。当我尝试编译时,出现以下错误:

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':
...

当我将以下参数添加到编译器时,我得到一个不同的错误:

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':
...

有人有什么想法吗?

【问题讨论】:

  • 链接你的库之后你的目标代码文件。 IE。将它们 last 放在您的链接行上。 cc -o tun2iot iot.o tun2iot.o -lssl -lcrypto
  • 啊,非常感谢!您应该将此作为答案发布!
  • 它已经在某处。我懒得追捕骗子,但我知道它就在那里。我以后可能会试试。这里太晚了。需要睡觉。无论如何,很高兴你已经启动并运行。

标签: c ssl linker ubuntu-12.04 undefined-reference


【解决方案1】:

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

此命令行不正确。参见例如this 解释一下。

【讨论】:

    猜你喜欢
    • 2018-02-09
    • 1970-01-01
    • 2020-10-30
    • 2018-01-04
    • 1970-01-01
    • 2013-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多