3
votes

I'm trying to compile a 32 bit binary that uses openssl on a debian wheezy 64 bit host.

I've followed what I believe is the recommended approach of adding the i386 architecture and installing libssl1.0.0:i386.

Just a simple test program fails to link:

#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 without the -m32 works fine.

I do have a 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 shows 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/x86_64-linux-gnu/4.7/../../../../lib32/crti.o /usr/lib/gcc/x86_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-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/4.7/32/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../lib32/crtn.o

This seems to show that it is searching /usr/lib/i386-linux-gnu/, which is where the libssl.so.1.0.0 is.

The files all seem 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

The other thing I thought of trying was installing libssl-dev:i386, but trying to install this wants to remove the 64bit gcc & g++ compilers and the 64bit libssl-dev, which makes me think it's not the right thing to do (and might stop me building 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've tried googling around; I've found other people with the same problem, but no solution.

1

1 Answers

3
votes

According to askubuntu the debian wheezy libssl-dev package in wheezy is broken / not multi arch compatible. It seems to be fixed in testing (jessie) and possibly also in Ubuntu 14.04 (maybe earlier ubuntu's too).

The following at least fixes the linker error:

cd /usr/lib/i386-linux-gnu/
ln -s libssl.so.1.0.0  libssl.so 
ln -s libcrypto.so.1.0.0 libcrypto.so