【问题标题】:Linking ssl library链接 ssl 库
【发布时间】:2017-05-07 19:31:17
【问题描述】:

我正在尝试将 ssl 库链接到我的编译命令。我是通过

安装的
sudo apt-get install libssl-dev

任何我的编译命令

g++ -Wall -pedantic -std=c++11 -lcrypto -lssl file.cpp

但它抱怨:

:(.text+0x19b): undefined reference to `SSL_library_init'
:(.text+0x1a0): undefined reference to `SSLv23_client_method'
:(.text+0x1a8): undefined reference to `SSL_CTX_new'
:(.text+0x1ff): undefined reference to `SSL_CTX_ctrl'
:(.text+0x20e): undefined reference to `SSL_new'
:(.text+0x26b): undefined reference to `SSL_set_fd'
:(.text+0x2b6): undefined reference to `SSL_get_peer_certificate'
:(.text+0x399): undefined reference to `PEM_write_X509'
:(.text+0x41d): undefined reference to `SSL_write'
(.text+0x511): undefined reference to `SSL_read'

所有来源都表明我的链接是正确的。我对加密库有同样的问题,但使用安装命令修复了它(好像我没有它)

我正在运行 Ubuntu。

【问题讨论】:

  • 你能发布整个链接器输出吗?它甚至找到了你的 libssl 和 libcrypto 吗?:

标签: c++ ssl compiler-errors compilation


【解决方案1】:

注意ssl 应该放在crypto 之前。 您也可以尝试将“/usr/local/ssl/lib”添加到链接器搜索路径:

g++ -Wall -pedantic -std=c++11 -lssl -lcrypto file.cpp -L/usr/local/ssl/lib

【讨论】:

    【解决方案2】:

    您可以尝试像这样静态链接它:

    g++ -Wall -pedantic -std=c++11 /usr/lib64/libcrypto.a file.cpp
    

    g++ -Wall -pedantic -std=c++11 /usr/lib/libcrypto++.a file.cpp
    

    g++ -Wall -pedantic -std=c++11 /usr/lib/x86_64-linux-gnu/libcrypto.a file.cpp
    

    g++ -Wall -pedantic -std=c++11 /usr/lib64/libcrypto.so file.cpp
    

    根据文件在您设备上的位置,选择上述其中一项

    【讨论】:

      猜你喜欢
      • 2010-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多