Reputation: 33511
I have an application that I want to link statically to the OpenSSL library (because the OS-provided version is too old).
I have built the OpenSSL library for this device (it is an old ARM embedded device), and linking against the .so
files works fine:
~$ /usr/local/arm-linux/bin/arm-linux-gcc «my own objects» -ldl -lresolv -lsms -lssl -Wall -o «binary»
Now, I want to build against the .a
files, but I don't seem to get the right command. The best I get it this:
~$ /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»
But, this gives the following unfound references:
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
Different commands, in where I change the order, or plainly leave out libcrypto.a
or libssl.a
yield different results (all undefined references).
How can I link statically against the OpenSSL .a
libraries?
Update When I unpack the .a
files using ar x «library.a»
, and link against the resulting .o
files, the build succeeds.
Update This is the output of 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
Upvotes: 0
Views: 1752
Reputation: 213516
How can I link statically against the OpenSSL .a libraries?
Your library order is wrong: libcrypto.a
depends on libssl.a
, so it must be listed before libssl.a
on the link line.
See this post for detailed explanation.
Upvotes: 1