Compiling a 32 bit binary that uses ssl on 64 bit Debian tiered hosting
I am trying to compile a 32 bit binary that uses openssl on a 64 bit debian wheezy host.
I've followed what I think is the recommended method of adding the i386 architecture and installing libssl1.0.0: i386.
Just a simple test program doesn't bind:
#include <openssl/ssl.h>
int main(void)
{
SSL_load_error_strings();
return 0;
}
$ gcc -m32 -lssl -o test -Wall test.c
/usr/bin/ld: cannot find -lssl
collect2: error: ld returned 1 exit status
This same command works fine without -m32.
I have 32 bit libssl:
$ locate libssl | grep i386
/usr/lib/i386-linux-gnu/libssl.so.1.0.0
/usr/lib/i386-linux-gnu/i586/libssl.so.1.0.0
/usr/lib/i386-linux-gnu/i686/cmov/libssl.so.1.0.0
Adding --verbose reveals the linker command:
/usr/lib/gcc/x86_64-linux-gnu/4.7/collect2 --sysroot = / - build-id --no-add-needed --eh-frame-hdr -m elf_i386 --hash-style = both -dynamic-linker / lib / ld-linux.so.2 -o test / usr / lib / gcc / x86_64- Linux-gnu / 4.7 /../../../../ lib32 / crt1. o / usr / lib / gcc / x 86_64-linux-gnu / 4.7 /../../../../ lib32 / crti.o / usr / lib / gcc / x 86_64-linux-gnu / 4.7 / 32 / crtbegin.o -L / usr / lib / i386-linux-gnu -L / usr / lib / gcc / x86_64-linux-gnu / 4.7 / 32 -L / usr / lib / gcc / x86_64-linux-gnu / 4.7 /../../../ i386-linux-gnu -L / usr / lib / gcc / x86_64-linux-gnu / 4.7 /../../../../ lib32 -L / lib / i386-linux- gnu -L / lib /../ lib32 -L / usr / lib / i386-linux-gnu -L / usr / lib /../ lib32 -L / usr / lib / gcc / x86_64-linux -gnu / 4.7 - L / usr / lib / gcc / x86_64-linux-gnu / 4.7 /../../../ i386-linux-gnu -L / usr / lib / gcc / x86_64-linux-gnu / 4.7 /../../ .. -L / lib / i386-linux-gnu -L / usr / lib / i386-linux-gnu -lssl / tmp / ccI9DoNH.o -lgcc -as-needed -lgcc_s --no-as- Necessary -lc -lgcc -as-needed -lgcc_s --no-as-needed / usr / lib / gcc / x86_64-linux-gnu / 4.7 / 32 / crtend.o / usr / lib / gcc / x 86_64-linux-gnu / 4.7 /../../../../ lib32 / crtn.o
It looks like it is looking for / usr / lib / i 386-linux-gnu / where libssl.so.1.0.0 is located.
The files appear to be valid according to file
:
/usr/lib/i386-linux-gnu/libssl.so.1.0.0: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, BuildID[sha1]=0x56052e2cdbad1207690499400909c6c87209735a, stripped
/usr/lib/i386-linux-gnu/i586/libssl.so.1.0.0: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, BuildID[sha1]=0x620bde79657c57fe5ef098d3648ccc2ce4bdb232, stripped
/usr/lib/i386-linux-gnu/i686/cmov/libssl.so.1.0.0: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, BuildID[sha1]=0x89b973943dfc314c56231d48eddad5fe785f6b12, stripped
Another thing I thought about trying to install libssl-dev: i386, but when trying to install that wants to uninstall 64-bit gcc and g ++ compilers and 64-bit libssl-dev, which makes me think that this is not the right thing to do (and might get in the way me create 64 bit binaries):
# apt-get install libssl-dev:i386
<..>
The following packages will be REMOVED:
build-essential cpp g++ g++-multilib gcc gcc-multilib libssl-dev lib tool
<..>
I tried to walk; I found other people with the same problem but no solution.
source to share
According to askubuntu , the debian wheezy libssl-dev package in wheezy is broken / incompatible across multiple arcs . It seems to have been fixed in testing (jessie) and possibly also in Ubuntu 14.04 (possibly earlier than ubuntu).
Below is at least the linker bug fixed:
cd /usr/lib/i386-linux-gnu/
ln -s libssl.so.1.0.0 libssl.so
ln -s libcrypto.so.1.0.0 libcrypto.so
source to share