[SOLVED] compiling a static 32 bit binary which will run on a 64 bit os.
SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
compiling a static 32 bit binary which will run on a 64 bit os.
Can this be done?
I'm trying to compile a static binary on a 32 bit machine which can run anywhere.
My build environment is Slackware 13.37 with rebuilt versions of certain library packages (SDL being the main one) which include the ".a" static library files. In order to do this, I've used the stock Slackbuilds from the Slackware source tree, with the only change being the removal of "--disable-static" from the SlackBuild file, [and/or insertion of "--enable-static" if necessary].
After compiling my static binary, the result I get is a file which runs fine on a 32 bit machine and a 64 bit 'multilib' setup. But attempting to run it on a pure 64 bit OS yields output containing words to the effect of "file not found".
ldd tells me that my binary is not dynamically linked (which is what I want).
I'm trying to avoid the need to provide a separate 64 bit package in addition to the 32 bit one. Is it possible?
I'm trying to compile a static binary on a 32 bit machine which can run anywhere.
After compiling my static binary, the result I get is a file which runs fine on a 32 bit machine and a 64 bit 'multilib' setup. But attempting to run it on a pure 64 bit OS yields output containing words to the effect of "file not found".
A simple test program linking only to libc worked ok here. Compiled on 32-bit Slackware, with -static, runs fine on a pure 64-bit Slackware. (Slackware 64-bit kernel uses CONFIG_IA32_EMULATION=y, without that it would not work.)
What does 'strace a.out' say (if your binary is called a.out) ? Maybe you can see which file is not found.
If I compile a test program without '-static' the output contains
Code:
INTERP 0x000134 0x08048134 0x08048134 0x00013 0x00013 R 0x1
[Requesting program interpreter: /lib/ld-linux.so.2]
and it won't run on the 64-bit system because the 32-bit dynamic loader is missing. And strace will print out exactly similar output to what you get. But if I use '-static', the output does not request the dynamic loader and the program runs on the 64-bit system.
And strace will print out exactly similar output to what you get.
Well this is embarrassing...
It turns out that I wasn't actually using the -static option. So, you are right!
But now I have a different problem.
Toward the end of the compile, I get an error which says:
Code:
/usr/lib/libSDL.a(SDL_sysloadso.o): In function `SDL_LoadObject':
SDL_sysloadso.c:(.text+0x1b): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/i486-slackware-linux/4.7.1/../../../../i486-slackware-linux/bin/ld: cannot find -lX11
/usr/lib/gcc/i486-slackware-linux/4.7.1/../../../../i486-slackware-linux/bin/ld: cannot find -lXext
/usr/lib/gcc/i486-slackware-linux/4.7.1/../../../../i486-slackware-linux/bin/ld: cannot find -lXrandr
/usr/lib/gcc/i486-slackware-linux/4.7.1/../../../../i486-slackware-linux/bin/ld: cannot find -lXrender
/usr/lib/gcc/i486-slackware-linux/4.7.1/../../../../i486-slackware-linux/bin/ld: cannot find -lvga
backends/libbackends.a(timidity.o): In function `MidiDriver_TIMIDITY::host_to_addr(char const*):
/home/rob/packages/scummvm/scummvm-1.6.0/backends/midi/timidity.cpp:288: warning: Using 'getbyhostname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: error: ld returned 1 exit status
make: *** [scummvm-static] Error 1
rob@here:~/packages/scummvm/scummvm-1.6.0$
Some libraries in Slackware are shipped without their static counterparts. This means you can't generate a static binary if the program depends on them. My impression is those libraries listed in the error message are in that situation.
backends/libbackends.a(timidity.o): In function `MidiDriver_TIMIDITY::host_to_addr(char const*):
timidity.cpp:288: warning: Using 'getbyhostname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
Depending of what /etc/nsswitch.conf contains, libc uses different methods to resolve host names to ip addresses. So even the static libc has to load dynamically one of the /lib/libnss_*.so, for example /lib/libnss_files.so.2 and /lib/libnss_dns.so.2 if you have 'hosts: files dns' in nsswitch.conf.
Quote:
/usr/lib/libSDL.a(SDL_sysloadso.o): In function `SDL_LoadObject':
SDL_sysloadso.c.text+0x1b): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
This wants to use dlopen. It's the interface to the dynamic loader to open a shared library.
So, you found two places which need the dynamic loader. You might be able to get rid of it if you can remove some code but you would probably lose some functionality as well.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.