Page 1 of 1

How to make gcc cross compiler (for i386) on 64 bit puppy?

Posted: Mon 04 Nov 2013, 16:06
by snayak
Dear All,

When I got my 64bit laptop, running Fatdog 611, I am missing my 32bit application development.

What is the procedure to compile gcc source to create a cross compiler which can produce i386 executable, on Fatdog 611?

Please suggest.

Sincerely,
Srinivas Nayak

Posted: Tue 05 Nov 2013, 09:44
by snayak
I did this.

Code: Select all

wget ftp://ftp.gnu.org/gnu/binutils/binutils-2.23.tar.gz

wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz

wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.6.2/gcc-core-4.6.2.tar.bz2

tar xvzf binutils-2.23.tar.gz 

bunzip2 gmp-4.3.2.tar.bz2
tar xvf gmp-4.3.2.tar
   
bunzip2 mpfr-2.4.2.tar.bz2
tar xvf mpfr-2.4.2.tar 
   
tar zxvf mpc-0.8.1.tar.gz
   
bunzip2 gcc-core-4.6.2.tar.bz2
tar xvf gcc-core-4.6.2.tar 

mkdir src
mv gmp-4.3.2 mpc-0.8.1 mpfr-2.4.2 binutils-2.23 gcc-4.6.2 src
   
mkdir -p opt/cross
   
export PREFIX="$HOME/opt/cross"
export TARGET=i586-elf
export PATH="$PREFIX/bin:$PATH"
   
cd $HOME/src
mkdir build-binutils
cd build-binutils
../binutils-2.23/configure --target=$TARGET --prefix="$PREFIX" --disable-nls
make
make install

mv gmp-4.3.2 gcc-4.6.2/gmp
mv mpc-0.8.1 gcc-4.6.2/mpc
mv mpfr-2.4.2 gcc-4.6.2/mpfr
mkdir build-gcc
cd build-gcc
../gcc-4.6.2/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c --without-headers
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc

$HOME/opt/cross/bin/$TARGET-gcc --version
   
#to add cross compiler location to system path   
#export PATH="$HOME/opt/cross/bin:$PATH"
Got a working compiler...


Sincerely,
Srinivas Nayak

Posted: Wed 06 Nov 2013, 07:25
by Ibidem
You also need a libc. Not sure how to go about that if you aren't going to use musl (musl-libc.org).

Posted: Wed 06 Nov 2013, 07:48
by snayak
Yes Ibidem, I need a library.
For the time being compiler is only ready.

Posted: Wed 06 Nov 2013, 09:42
by amigo
So, now use your new linker and compiler to compile glibc -it should be the same version as that used on the target system, and it should use the same patches (if any) and configuration options as the target systems' glibc. Be sure to use your separate prefix as for binutils and gcc.

Then when compiling apps for the target, you need to export LD_LIBRARY_PATH to the toolchain so that linking is done against the 32-bit libs above. If the app you want to compile rewuires other lobs besides glibc, then you'll need to compile and (subdir) install them before building.

Lot's of luck -cross-compiling can be a nightmare -even when things go well...

Posted: Thu 07 Nov 2013, 05:10
by snayak
By the way, with my default 64bit gcc, is it possible to use -m32 option to create a i386 executable?

I got

Code: Select all

~# gcc -march=i386 a.c
a.c:1:0: error: CPU you selected does not support x86-64 instruction set
a.c:1:0: error: CPU you selected does not support x86-64 instruction set
~#

Code: Select all

~# gcc -m32 a.c
/usr/lib64/gcc/x86_64-t2-linux-gnu/4.6.2/../../../../lib/crt1.o: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
~#
Any hope?

Sincerely,
Srinivas Nayak

Posted: Thu 07 Nov 2013, 06:30
by amigo
For -m32 to work, you need to build a multi-target, multi-lib compiler.

Re: How to make gcc cross compiler (for i386) on 64 bit puppy?

Posted: Thu 07 Nov 2013, 13:31
by jamesbond
snayak wrote:What is the procedure to compile gcc source to create a cross compiler which can produce i386 executable, on Fatdog 611?
http://crosstool-ng.org/
Or if you are too lazy http://www.landley.net/aboriginal/downl ... 86.tar.bz2.

And beware of what amigo said, this is so true:
amigo wrote:Lot's of luck -cross-compiling can be a nightmare -even when things go well...