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

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
snayak
Posts: 422
Joined: Wed 14 Sep 2011, 05:49

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

#1 Post 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
[Precise 571 on AMD Athlon XP 2000+ with 512MB RAM]
[Fatdog 720 on Intel Pentium B960 with 4GB RAM]

[url]http://srinivas-nayak.blogspot.com/[/url]

snayak
Posts: 422
Joined: Wed 14 Sep 2011, 05:49

#2 Post 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
Last edited by snayak on Wed 06 Nov 2013, 07:47, edited 1 time in total.
[Precise 571 on AMD Athlon XP 2000+ with 512MB RAM]
[Fatdog 720 on Intel Pentium B960 with 4GB RAM]

[url]http://srinivas-nayak.blogspot.com/[/url]

Ibidem
Posts: 549
Joined: Wed 26 May 2010, 03:31
Location: State of Jefferson

#3 Post 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).

snayak
Posts: 422
Joined: Wed 14 Sep 2011, 05:49

#4 Post by snayak »

Yes Ibidem, I need a library.
For the time being compiler is only ready.
[Precise 571 on AMD Athlon XP 2000+ with 512MB RAM]
[Fatdog 720 on Intel Pentium B960 with 4GB RAM]

[url]http://srinivas-nayak.blogspot.com/[/url]

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#5 Post 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...

snayak
Posts: 422
Joined: Wed 14 Sep 2011, 05:49

#6 Post 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
[Precise 571 on AMD Athlon XP 2000+ with 512MB RAM]
[Fatdog 720 on Intel Pentium B960 with 4GB RAM]

[url]http://srinivas-nayak.blogspot.com/[/url]

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#7 Post by amigo »

For -m32 to work, you need to build a multi-target, multi-lib compiler.

jamesbond
Posts: 3433
Joined: Mon 26 Feb 2007, 05:02
Location: The Blue Marble

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

#8 Post 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...
Fatdog64 forum links: [url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Latest version[/url] | [url=https://cutt.ly/ke8sn5H]Contributed packages[/url] | [url=https://cutt.ly/se8scrb]ISO builder[/url]

Post Reply