【问题标题】:Building OpenSSL and LibCURL from sources (Ubuntu) with undefined references使用未定义的引用从源代码(Ubuntu)构建 OpenSSL 和 LibCURL
【发布时间】:2018-06-27 13:11:13
【问题描述】:

我正在尝试将 .dll 项目从 Windows 移植到 Linux,我需要构建 OpenSSLcURL 静态。为此,我也尝试编译zlib,但出现一些我无法解决的错误。

我没有使用sudo,除了zlib$ sudo make install(因为我将它安装在默认位置/usr/local/)。这就是我安装其中 3 个的方式:

zlib(来自 $HOME/software/zlib-1.2.11)

  • $ ./configure --static
  • $ make V=1
  • $ make test好的
  • $ sudo make install 安装在/usr/local/lib 中没有错误

openSSL1.1.0g(来自 $HOME/software/openSSL1.1.0g)

  • $ LIBS="-lcrypto -lz -ldl" ./config -fPIC -static --debug zlib no-zlib-dynamic --prefix=$HOME/<project_path>/openssl/openssl_debug_64bit_static-linux enable-ssl2 enable-ssl3 enable-ssl3-method no-shared no-threads
  • $ make V=1
  • $ make test好的
  • $ make install 安装在指定位置且没有错误

curl(来自 $HOME/software/curl-7.57.0)

  • $ LIBS="-lssl -lcrypto -lz -ldl" ./configure --disable-shared --with-ssl=$HOME/<project_path>/openssl/openssl_debug_64bit_static-linux --enable-debug --prefix=$HOME/<project_path>/libcurl64-linux/debug/ --without-librtmp --without-ca-bundle --disable-ldap --disable-pthreads --disable-threaded-resolver --enable-static
  • $ make V=1
  • $ make test 他们运行了很长时间,其中 4 个失败了,但我检查了 test cases,它们与 TFTPmultiprotocol 相关(起初不相关)
  • $ make install 安装在指定位置且没有错误

我仍然遇到类似的问题:

../src/openssl/openssl_debug_64bit_static-linux/lib/libcrypto.a(c_zlib.o): In function `zlib_stateful_init':
/home/jjimenez/software/openssl-1.1.0g/crypto/comp/c_zlib.c:136: undefined reference to `inflateInit_'
/home/jjimenez/software/openssl-1.1.0g/crypto/comp/c_zlib.c:145: undefined reference to `deflateInit_'
../src/openssl/openssl_debug_64bit_static-linux/lib/libcrypto.a(c_zlib.o): In function `zlib_stateful_finish':
/home/jjimenez/software/openssl-1.1.0g/crypto/comp/c_zlib.c:160: undefined reference to `inflateEnd'
/home/jjimenez/software/openssl-1.1.0g/crypto/comp/c_zlib.c:161: undefined reference to `deflateEnd'
../src/openssl/openssl_debug_64bit_static-linux/lib/libcrypto.a(c_zlib.o): In function `zlib_stateful_compress_block':
/home/jjimenez/software/openssl-1.1.0g/crypto/comp/c_zlib.c:180: undefined reference to `deflate'

我没有得到的东西:

  1. 为什么它指的是我从 (/home/jjimenez/software/openssl-1.1.0g) 构建源代码的位置?它应该创建一个静态库并将它需要的每个符号放在.a 中,不是吗?

  2. 如果我执行这个nm -gC /usr/local/lib/libz.a | grep inflateInit_,我会得到这个输出:

00000000000005a0 T inflateInit_ U inflateInit_

但是,执行 nm -gC libcrypto.a | grep inflateInit_(从安装了 openSSL 的内部)我得到:

                 U inflateInit_

从我的found 来看,T 表示该符号确实存在并且位于code 部分。为什么它还与U(符号未定义)一起出现?我不能假设在链接到这个库时应该找到它吗?这里肯定有一些奇怪的东西。

任何帮助将不胜感激。

【问题讨论】:

  • 首先,安装包libcurl4-openssl-devlibssl-dev
  • @LorinczyZsigmond 我刚刚安装了libcurl4-openssl-dev。看起来 libssl-dev 已安装 (0 upgraded, 0 newly installed, 0 to remove and 76 not upgraded.)
  • 那么你应该可以编译和链接你自己的程序了。
  • @LorinczyZsigmond 我又做了一次(就像问题中提到的那样),我得到了同样的链接错误:S
  • 请说明您在构建自己的应用程序时收到的第一条错误消息(您无法解决。)

标签: c linux ssl curl build


【解决方案1】:

最后,多亏了一位队友,我终于解决了。

静态链接没有像我想象的那样工作,所以zlib 符号不包含在libcrypto.a 中。我只需将前者添加到 CMake 编译中,链接器就可以正常运行这些错误。

【讨论】:

    猜你喜欢
    • 2017-05-23
    • 1970-01-01
    • 2021-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-26
    • 1970-01-01
    相关资源
    最近更新 更多