Re: cross-compiling on 64 to 32-bit Linuxlocalhost/
You don't need to specify -m32 if you have a tool set prefixed with the cross tag. The reason for using -m32 is because the user wants to use his 64-bit gcc to compile 32-bit code, so he has to tell the compiler to switch to 32-bit mode also. (Incidentally, if you're running on Linux, might also be a good idea to tell the compiler you're running in a 32-bit environment by executing gcc with linux32). Another way to use your 64-bit gcc without special compiler flags is to create scripts, named with the cross prefix, in your bin directory that execute the compiler in 32-bit mode (and perhaps also executed by linux32). Then these tools will be preferred by Autoconf when you use --host=. Thanks for your answer John, In fact I believed autoconf could have done all the job for me: that is invoking 64bit gcc with -m32 after having detected there is no i686-pc-linux-gnu compiler available :) But maybe it's rare to be in this situation? I'm building a closed source shared library that only depends on libc which is why I don't really need a chroot environment. For now, to ease my coworkers life, I came up with a shell script that does a little analysis before invoking configure: based on uname and gcc --print-multi-lib, it creates several build directories like build/linux/i386 and/or build/linux/x86_64 and invokes configure from there with proper CC overrides. Regards, Gregory
Re: cross-compiling on 64 to 32-bit Linuxlocalhost/
You need a bi-arch system, that is, one that has the system libraries both in a 64-bit variant and in a 32-bit variant (typically in /lib64 and /lib, respectively). For compiling in 32-bit mode, I use ./configure --host=i686-pc-linux-gnu \ --prefix=/arch/x86-linux/gnu \ CC=gcc -m32 -march=i586 \ CXX=g++ -m32 -march=i586 \ LDFLAGS=-m32 Hello, I'm curious about why setting --host=i686-pc-linux-gnu is not enough to achieve cross compiling and why in that case it's not up to autoconf to add -m32 to CC. I know the autoconf manual says you're better of using CC=gcc -m32 or CC=gcc -m64 (see http://www.gnu.org/software/autoconf/manual/autoconf.html#index-CFLAGS-79 ). But somehow, it feels weird to write CC=gcc -m32 when one purpose of autoconf is actually to select a compiler for you. Isn't there another way around CC=gcc -m32 or CFLAGS=-m32? Or are -m32 and -m64 peculiarities of GCC only? Regards, Gregory
Re: cross-compiling on 64 to 32-bit Linuxlocalhost/
Hi Gregory, On 3/2/2010 4:14 PM, Grégory Pakosz wrote: ./configure --host=i686-pc-linux-gnu \ --prefix=/arch/x86-linux/gnu \ CC=gcc -m32 -march=i586 \ CXX=g++ -m32 -march=i586 \ LDFLAGS=-m32 I'm curious about why setting --host=i686-pc-linux-gnu is not enough to achieve cross compiling and why in that case it's not up to autoconf to add -m32 to CC. You don't need to specify -m32 if you have a tool set prefixed with the cross tag. The reason for using -m32 is because the user wants to use his 64-bit gcc to compile 32-bit code, so he has to tell the compiler to switch to 32-bit mode also. (Incidentally, if you're running on Linux, might also be a good idea to tell the compiler you're running in a 32-bit environment by executing gcc with linux32). Another way to use your 64-bit gcc without special compiler flags is to create scripts, named with the cross prefix, in your bin directory that execute the compiler in 32-bit mode (and perhaps also executed by linux32). Then these tools will be preferred by Autoconf when you use --host=. Regards, John