如何针对静态 OpenSSL 库编译应用程序?
How to compile an application against the static OpenSSL library?
我有一个应用程序想 link 静态地连接到 OpenSSL 库(因为 OS 提供的版本太旧)。
我已经为这个设备构建了 OpenSSL 库(它是一个旧的 ARM 嵌入式设备),link针对 .so
文件工作正常:
~$ /usr/local/arm-linux/bin/arm-linux-gcc «my own objects» -ldl -lresolv -lsms -lssl -Wall -o «binary»
现在,我想针对 .a
文件进行构建,但我似乎没有得到正确的命令。最好的我得到它:
~$ /usr/local/arm-linux/bin/arm-linux-gcc «my own objects» -ldl -lresolv -lsms -Wall /usr/local/arm-linux/lib/libssl.a /usr/local/arm-linux/lib/libcrypto.a -o «binary»
但是,这给出了以下未找到的引用:
digest.o(.text+0x48): In function `digest_get_hash':
: undefined reference to `OPENSSL_init_crypto'
digest.o(.text+0x78): In function `digest_get_hash':
: undefined reference to `EVP_MD_CTX_new'
digest.o(.text+0xf4): In function `digest_get_hash':
: undefined reference to `EVP_MD_CTX_free'
ssl.o(.text+0x1c): In function `_ssl_initialise_context':
: undefined reference to `OPENSSL_init_crypto'
ssl.o(.text+0x2c): In function `_ssl_initialise_context':
: undefined reference to `OPENSSL_init_ssl'
ssl.o(.text+0x30): In function `_ssl_initialise_context':
: undefined reference to `TLS_client_method'
ssl.o(.text+0xc0): In function `ssl_init':
: undefined reference to `OPENSSL_init_ssl'
collect2: ld returned 1 exit status
不同的命令,在我更改顺序的地方,或者直接省略 libcrypto.a
或 libssl.a
会产生不同的结果(所有未定义的引用)。
我如何link 静态地针对 OpenSSL .a
库?
Update 当我使用 ar x «library.a»
解压缩 .a
文件,并针对生成的 .o
文件 link 时,构建成功。
更新 这是gcc -v
的输出:
[bf@localhost src]$ /usr/local/arm-linux/bin/arm-linux-gcc -v
Reading specs from /usr/local/arm-linux/bin/../lib/gcc-lib/arm-linux/3.3.2/specs
Configured with: ../configure --target=arm-linux --disable-shared --with-headers=/home/gerg/new-wave.xscale/linux-2.4.x/include --with-gnu-as --with-gnu-ld --enable-multilib
Thread model: posix
gcc version 3.3.2
How can I link statically against the OpenSSL .a libraries?
您的图书馆顺序错误:libcrypto.a
取决于 libssl.a
,因此 必须 在 [=21] 上的 libssl.a
之前列出=]行。
详见this post。
我有一个应用程序想 link 静态地连接到 OpenSSL 库(因为 OS 提供的版本太旧)。
我已经为这个设备构建了 OpenSSL 库(它是一个旧的 ARM 嵌入式设备),link针对 .so
文件工作正常:
~$ /usr/local/arm-linux/bin/arm-linux-gcc «my own objects» -ldl -lresolv -lsms -lssl -Wall -o «binary»
现在,我想针对 .a
文件进行构建,但我似乎没有得到正确的命令。最好的我得到它:
~$ /usr/local/arm-linux/bin/arm-linux-gcc «my own objects» -ldl -lresolv -lsms -Wall /usr/local/arm-linux/lib/libssl.a /usr/local/arm-linux/lib/libcrypto.a -o «binary»
但是,这给出了以下未找到的引用:
digest.o(.text+0x48): In function `digest_get_hash':
: undefined reference to `OPENSSL_init_crypto'
digest.o(.text+0x78): In function `digest_get_hash':
: undefined reference to `EVP_MD_CTX_new'
digest.o(.text+0xf4): In function `digest_get_hash':
: undefined reference to `EVP_MD_CTX_free'
ssl.o(.text+0x1c): In function `_ssl_initialise_context':
: undefined reference to `OPENSSL_init_crypto'
ssl.o(.text+0x2c): In function `_ssl_initialise_context':
: undefined reference to `OPENSSL_init_ssl'
ssl.o(.text+0x30): In function `_ssl_initialise_context':
: undefined reference to `TLS_client_method'
ssl.o(.text+0xc0): In function `ssl_init':
: undefined reference to `OPENSSL_init_ssl'
collect2: ld returned 1 exit status
不同的命令,在我更改顺序的地方,或者直接省略 libcrypto.a
或 libssl.a
会产生不同的结果(所有未定义的引用)。
我如何link 静态地针对 OpenSSL .a
库?
Update 当我使用 ar x «library.a»
解压缩 .a
文件,并针对生成的 .o
文件 link 时,构建成功。
更新 这是gcc -v
的输出:
[bf@localhost src]$ /usr/local/arm-linux/bin/arm-linux-gcc -v
Reading specs from /usr/local/arm-linux/bin/../lib/gcc-lib/arm-linux/3.3.2/specs
Configured with: ../configure --target=arm-linux --disable-shared --with-headers=/home/gerg/new-wave.xscale/linux-2.4.x/include --with-gnu-as --with-gnu-ld --enable-multilib
Thread model: posix
gcc version 3.3.2
How can I link statically against the OpenSSL .a libraries?
您的图书馆顺序错误:libcrypto.a
取决于 libssl.a
,因此 必须 在 [=21] 上的 libssl.a
之前列出=]行。
详见this post。