引用了一堆尚未解决的OpenSSL符号的错误显然存在? [英] Errors that refer to a bunch of unresolved OpenSSL symbols that clearly exist?

查看:179
本文介绍了引用了一堆尚未解决的OpenSSL符号的错误显然存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个共享库(我们称之为foo),它使用了另一个库(我们称之为bar)。 bar利用了OpenSSL的一些功能。



这里是问题出现的地方。

bar被编译为一个静态库,看起来OpenSSL也是。因此,当我链接库(foo)时,我包括:


$ b

  • 用于foo的对象文件

  • 静态库 libbar.a

  • OpenSSL静态库 libcrypto.a libssl.a



build命令看起来像这样:

  g ++ -Wl,-soname,libfoo.so -shared file1.o file2.o libbar.a \ 
libcrypto.a libssl.a -o libfoo.so

然而,我得到了很多错误:

  ld:./obj/libbar.a(file1.co):in function initialize_openssl:
ssl。 c:117:error:未定义引用'SSL_library_init'

运行以下命令:

  nm libssl.a | grep SSL_library_init 

生成以下输出:

  00000000 T SSL_library_init 

所以显然没有错OpenSSL库。什么可能导致这样的事情?以下是用于构建OpenSSL的三个命令:

  export cross = arm-linux-androideabi- 
./Configure android --prefix =〜/ openssl-arm
make CC =$ {cross} gccAR =$ {cross} ar rRANLIB =$ {cross} ranlib

编译过程没有任何错误,所以我完全不知所措。



为什么我得到的链接器错误指的是一堆明显存在的OpenSSL符号?

解决方案

链接命令中库的顺序。切换 libcrypto.a libssl.a 解析了所有的符号。



默认情况下,GCC使用 LD 。如果您有两个库,如特定顺序链接的 libssl libcrypto ,则表示 libssl 取决于 libcrypto 中的符号。因此, libssl 必须位于 libcrypto (或 libcrypto 的libssl )。因为 libcrypto ,因此 libssl 依赖于 libcrypto 提供由 libssl 使用的加密。


I am building a shared library (we'll call it "foo") that makes use of another library (we'll call it "bar"). "bar" makes use of some functions from OpenSSL.

Here's where the problem surfaces.

"bar" was compiled as a static library and it would appear that OpenSSL was too. So when I link the library ("foo"), I include the:

  • object files for "foo"
  • static library libbar.a
  • OpenSSL static libraries libcrypto.a and libssl.a

The build command looks something like this:

g++ -Wl,-soname,libfoo.so -shared file1.o file2.o libbar.a \
  libcrypto.a libssl.a -o libfoo.so

However, I get a ton of errors:

ld: ./obj/libbar.a(file1.c.o): in function initialize_openssl:
  ssl.c:117: error: undefined reference to 'SSL_library_init'

Running the following command:

nm libssl.a | grep SSL_library_init

Produces the following output:

00000000 T SSL_library_init

So obviously there is nothing wrong with the OpenSSL libraries. What could have possibly caused something like this? Here are the three commands used to build OpenSSL:

export cross=arm-linux-androideabi-
./Configure android --prefix=~/openssl-arm
make CC="${cross}gcc" AR="${cross}ar r" RANLIB="${cross}ranlib"

The compilation process completed without any errors, so I'm utterly baffled.

Why am I getting linker errors that refer to a bunch of OpenSSL symbols that clearly exist?

解决方案

The problem was caused by the order of the libraries in the link command. Switching the order of libcrypto.a and libssl.a resolved all of the symbols.

GCC uses LD by default, and its a single pass linker. When you have two libraries, like libssl and libcrypto linked in a particular order, it means libssl depends on symbols from libcrypto. Therefore, libssl must precede libcrypto (or libcrypto must follow libssl). It should be no surprise libssl relies upon libcrypto since libcrypto provides the crypto used by libssl.

这篇关于引用了一堆尚未解决的OpenSSL符号的错误显然存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆