2

I am having difficulties running 32bit code on my 64bit gentoo, the program is very simple:

#include <stdio.h>

main()
{
        printf("Hello World");    
}

I compiled it with gcc -m32 -o hello32 hello.c. The output seems correct:

ozn@yeni2gen:~$ gcc -m32 -o hello32 hello.c
ozn@yeni2gen:~$ file hello32 
hello32: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, not stripped

But when I try to run the file I get an error:

./hello32 
bash: ./hello32: No such file or directory

updated

ozn@yeni2gen:~$ bash --version
GNU bash, version 4.2.53(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>


ozn@yeni2gen:~$ gcc -v
Using built-in specs.
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.8.3/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.8.3/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.8.3/work/gcc-4.8.3/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.8.3 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.3/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.8.3 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.8.3/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.8.3/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.3/include/g++-v4 --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.8.3/python --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.8.3 p1.1, pie-0.5.9' --enable-libstdcxx-time --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64 --disable-altivec --disable-fixed-point --enable-targets=all --disable-libgcj --enable-libgomp --disable-libmudflap --disable-libssp --enable-lto --without-cloog --enable-libsanitizer
Thread model: posix
gcc version 4.8.3 (Gentoo 4.8.3 p1.1, pie-0.5.9) 

for those who are skeptic, the file is there:

ozn@yeni2gen:~$ ls -l hello32 
-rwxr-xr-x 1 ozn ozn 6825 May 31 19:04 hello32
oz123
  • 27,559
  • 27
  • 125
  • 187
  • 2
    Can you see the file in the expected directory with ls? – David W May 31 '15 at 17:13
  • This works just fine for me. Maybe include your specific version of GCC and bash. – user530873 May 31 '15 at 17:14
  • 1
    The error suggests the file is not in that directory. – GolezTrol May 31 '15 at 17:18
  • @GolezTrol, the file is there, how else does the command file works? – oz123 May 31 '15 at 17:21
  • @Oz123: No, you showed that `hello32` is in the `~` directory, but you're trying to run `~/./hello32`, which fails because you don't have a `.` folder. – Mooing Duck May 31 '15 at 17:27
  • @TBohne, you are wrong, if I compile the file without "-m32" I can run the file with ./hello32. – oz123 May 31 '15 at 17:40
  • 4
    You must install the 32 bit libraries. Can't help how you do this on Gentoo Linux. Probably `/lib/ld-linux.so.2` can't be found resulting in the `No such file or directory` message. – 4566976 May 31 '15 at 17:40
  • 1
    If the needed libraries weren't present, wouldn't the linker fail? – David W May 31 '15 at 17:44
  • 2
    What's the output from `ldd ./hello32`? – Andrew Henle May 31 '15 at 17:48
  • 1
    @DavidW Yes, that's true. Just renamed `/lib/ld-linux.so.2` on my Fedora Linux and 32 bit linker failed. – 4566976 May 31 '15 at 18:24
  • As 4566976 said, you need the 32 bit libraries. Maybe there is some package for your distribution named multilib. When the 32 bit libraries are missing you will get the "No such file or directory" error even though the executable is there. – Henrik Carlqvist May 31 '15 at 20:16
  • @AndrewHenle, the output is ldd hello32 not a dynamic executable – oz123 May 31 '15 at 20:46
  • @Oz123 - I'm not familiar with Gentoo. This page might be a good place to start: https://wiki.gentoo.org/wiki/Multilib – Andrew Henle May 31 '15 at 21:04
  • @Oz123 does `/lib/ld-linux.so.2` exist or not for you—and if it exists, does what it points to exist? What is your `/etc/make.profile` symlink? – binki Jun 01 '15 at 05:01
  • @Oz123 I get the same output from `ldd` on a 32 bit executable when `/lib/ld-linux.so.2` is absent. – 4566976 Jun 01 '15 at 15:33

1 Answers1

1

OK, thanks for the hints. Apparently, I am doing something wrong with my gentoo. After digging a lot in the gentoo forums, and thanks for the hints here, I found a solution:

(root)# ln -vs /lib32/ld-linux.so.2 /lib/ld-linux.so.2

The original discussion in the gentoo forums which gave me this hint.

oz123
  • 27,559
  • 27
  • 125
  • 187