Discussion:
Cannot cross compile ONE LINE PROGRAM, 64 to 32 bit
(too old to reply)
Ignoramus11000
2008-10-30 17:41:47 UTC
Permalink
Here's a program that I am trying to cross compile (obviously I am
working on a larger program, but this is a very simple illustration):

int main( int args, char **argv ) { return 0; }

Here's how I do it:

gcc -o exe -m32 q.c

Here's what I get:

~/tmp==>gcc -o exe -m32 q.c
/usr/bin/ld: skipping incompatible /lib/libc.so.6 when searching for /lib/libc.so.6
/usr/bin/ld: cannot find /lib/libc.so.6
collect2: ld returned 1 exit status

This is a Ubuntu Hardy machine, 64 bit, trying to cross compile for 32
bit. I installed a bunch of 32 bit libraries, but it does not
help. (ia32-libs gcc-4.2-multilib)
--
Due to extreme spam originating from Google Groups, and their inattention
to spammers, I and many others block all articles originating
from Google Groups. If you want your postings to be seen by
more readers you will need to find a different means of
posting on Usenet.
http://improve-usenet.org/
Michael B. Trausch
2008-10-30 19:01:24 UTC
Permalink
On Thu, 30 Oct 2008 12:41:47 -0500
Post by Ignoramus11000
Here's a program that I am trying to cross compile (obviously I am
int main( int args, char **argv ) { return 0; }
gcc -o exe -m32 q.c
~/tmp==>gcc -o exe -m32 q.c
/usr/bin/ld: skipping incompatible /lib/libc.so.6 when searching
for /lib/libc.so.6 /usr/bin/ld: cannot find /lib/libc.so.6
collect2: ld returned 1 exit status
This is a Ubuntu Hardy machine, 64 bit, trying to cross compile for 32
bit. I installed a bunch of 32 bit libraries, but it does not
help. (ia32-libs gcc-4.2-multilib)
You'll need 32-bit development headers and the like (try
libc6-dev-i386 as one such possible extra thing you'll likely need).
Your best bet if you'd like to do 32-bit development on a 64-bit system
(or, for that matter, cross-compiling from one platform to another one)
would be to create an area in your ${HOME} for the cross-compilers and
cross-compiled libraries to live, because you'll need to cross-compile
the libraries for the target system as well, and have their headers
available.

If your program is quite simple in nature and only carries a dependency
on 32-bit libc, then you should be able to get by with just installing
libc6-dev-i386. You should also be able to compile 32-bit libraries
for your application's use, should you need them, but I have not tested
that idea. I'd stick with using a complete cross-compiling toolchain,
myself. You can find information on those all over the Internet, but
here's a few resources to get you started:

http://www.kegel.com/crosstool/
http://www.airs.com/ian/configure/configure_5.html
http://gcc.gnu.org/wiki/Building_Cross_Toolchains_with_gcc

Also see the Wikipedia article on cross compilers, which contains a
good amount of references:

http://en.wikipedia.org/wiki/Cross-compiling

HTH,
Mike
--
My sigfile ran away and is on hiatus.
http://www.trausch.us/
Robert Heller
2008-10-31 15:18:59 UTC
Permalink
Post by Ignoramus11000
Here's a program that I am trying to cross compile (obviously I am
int main( int args, char **argv ) { return 0; }
gcc -o exe -m32 q.c
~/tmp==>gcc -o exe -m32 q.c
/usr/bin/ld: skipping incompatible /lib/libc.so.6 when searching for /lib/libc.so.6
/usr/bin/ld: cannot find /lib/libc.so.6
collect2: ld returned 1 exit status
This is a Ubuntu Hardy machine, 64 bit, trying to cross compile for 32
bit. I installed a bunch of 32 bit libraries, but it does not
help. (ia32-libs gcc-4.2-multilib)
You really can't use the 64-bit targeted compiler to compile for 32-bit.
You need to create the 32-bit targeted compiler as a cross-compiler. And
no, you really, really DON'T want to install the compiler from a 32-bit
distro on your 64-bit install.

The "ia32-libs gcc-4.2-multilib" is likely just the run-time to let you
run 32-bit apps on your 64-bit machine. And no, you really, really
DON'T want to install the 32-bit dev packages on your 64-bit system either.

It might just be easier to install vmware server and install a 32-bit
Ubuntu Hardy in a virtual machine. I've built cross-gcc compilers --
it is a bear -- not hard really, just a bear -- many tedious bits and
pieces -- of course this was a mess-windows targeted build tool set,
which only adds more 'fun' to the process.
--
Robert Heller -- Get the Deepwoods Software FireFox Toolbar!
Deepwoods Software -- Linux Installation and Administration
http://www.deepsoft.com/ -- Web Hosting, with CGI and Database
***@deepsoft.com -- Contract Programming: C/C++, Tcl/Tk
Michael B. Trausch
2008-10-31 19:37:23 UTC
Permalink
On Fri, 31 Oct 2008 10:18:59 -0500
Post by Robert Heller
You really can't use the 64-bit targeted compiler to compile for
32-bit. You need to create the 32-bit targeted compiler as a
cross-compiler. And no, you really, really DON'T want to install the
compiler from a 32-bit distro on your 64-bit install.
GCC treats x86/x86-64 as a single major system, with x86 and x86-64
being subtypes. That's why the -m32 flag is there; it just turns off
support for the 64-bit extensions and generates 32-bit PM code instead
of 64-bit LM code. You *can* use it that way just fine, assuming you
tell it where to find all the libs. It's really mostly useful for
one-off compiles of things that don't have complex dependencies, though.

This will contain information for you re: GCC's functionality. The
manual is pretty good quality, I would say:

sudo apt-get gcc-doc
info gcc

See "i386 and x86-64 Options", in the "Option Summary". Note that -m32
is not specific to i386/x86-64, it also exists on other systems where
there are 64-bit possibilities for compilation. Also remember that
x86-64 is a set of extensions and is (mostly) backward compatible when
in Long Mode. It's exactly backward compatible when in Protected
Mode. In Long Mode, though, v86 mode leaves the building.
Post by Robert Heller
The "ia32-libs gcc-4.2-multilib" is likely just the run-time to let
you run 32-bit apps on your 64-bit machine. And no, you really,
really DON'T want to install the 32-bit dev packages on your 64-bit
system either.
ia32-libs is runtime.

gcc-4.2-multilib provides the static libgcc that has to be used to
generate a 32-bit program, essentially adding support for -m32.

libc6-dev-i386 provides the dev libs for the C library for IA32 when
you're on x86-64, enabling -m32 to work for software depending on the
libc.

As far as installing dev libs, that's easy---put them in
${HOME}/opt/xgcc-32. Link them from there when you build your
software. 'tis not hard.
Post by Robert Heller
It might just be easier to install vmware server and install a 32-bit
Ubuntu Hardy in a virtual machine. I've built cross-gcc compilers --
it is a bear -- not hard really, just a bear -- many tedious bits and
pieces -- of course this was a mess-windows targeted build tool set,
which only adds more 'fun' to the process.
I suggested having a self-hosted cross-toolchain because it makes life
easier. You set it up and then create a shell script to instantiate
your cross-development environment by populating the environment
variables in your shell and you're good to go. But, you can do it
either way. You can even detect that you're on a 64-bit system and if
you really want to build a 32-bit program, do so by handling that in
your configure or scons or whatever build system you use. In the end,
the most easily reproducible and stable environment for cross
development usually tends to be the scripts that generate
cross-compiling toolchains for you, though, and then you can have
*several* of them. If you're cross-compiling to provide packaging,
this is awfully convenient.

--- Mike
--
My sigfile ran away and is on hiatus.
http://www.trausch.us/
Loading...