In reading the gcc man page, and information from, say, AMD, I get the impression that gcc can generate executables on an x86-64 box that will run on a 32 bit machine. But I can't make it work.
I'm using SuSE 10.3 on a "Intel(R) Core(TM)2 CPU 4400 @ 2.00GHz stepping 02".
The gcc man page says:
-march=cpu-type Generate instructions for the machine type cpu-type. The choices for cpu- type are the same as for -mtune. Moreover, specifying -march=cpu-type implies -mtune=cpu-type.
Trying -march=i386 gives:
cc -g -I/home/mellman/src/ulib -o cross.o -march=i386 cross.c cross.c:1: error: CPU you selected does not support x86-64 instruction set cross.c:1: error: CPU you selected does not support x86-64 instruction set
Right. That's the point...
And -march=i686 gives:
cc -g -I/home/mellman/src/ulib -o cross.o -march=i686 cross.c cross.c:1: error: CPU you selected does not support x86-64 instruction set
(just once this time)
On a lark (because I don't find an explanation in the man page of what the difference with -march is), I tried -m32:
Here I get:
cc -g -I/home/mellman/src/ulib -o cross.o -m32 cross.c In file included from /usr/include/features.h:345, from /usr/include/stdio.h:28, from cross.c:1: /usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory
stubs-32.h is not on my system, and I can't find it on SuSE's site either.
I find almost nothing about this when googling. WRT stubs-32.h, the only thing I can find says to use different libraries (!). The response is always that that didn't help.
It would seem that this is a pretty common requirement - I have a 64 bit box at home and want to distribute my programs generally (like to my virtual server, which only has 32 bits). The lack of general interest here must indicate that I'm completely on the wrong track somehow...
> In reading the gcc man page, and information from, say, AMD, I get > the impression that gcc can generate executables on an x86-64 box > that will run on a 32 bit machine. But I can't make it work.
> I'm using SuSE 10.3 on a "Intel(R) Core(TM)2 CPU 4400 @ 2.00GHz > stepping 02".
> The gcc man page says:
> -march=cpu-type > Generate instructions for the machine type cpu-type. The choices for > cpu- > type are the same as for -mtune. Moreover, specifying -march=cpu-type > implies -mtune=cpu-type.
> Trying -march=i386 gives:
> cc -g -I/home/mellman/src/ulib -o cross.o -march=i386 cross.c > cross.c:1: error: CPU you selected does not support x86-64 instruction > set > cross.c:1: error: CPU you selected does not support x86-64 instruction > set
> Right. That's the point...
> And -march=i686 gives:
> cc -g -I/home/mellman/src/ulib -o cross.o -march=i686 cross.c > cross.c:1: error: CPU you selected does not support x86-64 instruction > set
> (just once this time)
> On a lark (because I don't find an explanation in the man page of what > the difference with -march is), I tried -m32:
> Here I get:
> cc -g -I/home/mellman/src/ulib -o cross.o -m32 cross.c > In file included from /usr/include/features.h:345, > from /usr/include/stdio.h:28, > from cross.c:1: > /usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or > directory
> stubs-32.h is not on my system, and I can't find it on SuSE's site > either.
> I find almost nothing about this when googling. WRT stubs-32.h, the > only thing I can find says to use different libraries (!). The response > is always that that didn't help.
> It would seem that this is a pretty common requirement - I have a 64 bit > box at home and want to distribute my programs generally (like to my > virtual server, which only has 32 bits). The lack of general interest > here must indicate that I'm completely on the wrong track somehow...
On Wed, 26 Mar 2008 15:07:45 +0100, FÖLDY Lajos wrote: > On Wed, 26 Mar 2008, Charles T Smith wrote:
>> Hi.
>> In reading the gcc man page, and information from, say, AMD, I get the >> impression that gcc can generate executables on an x86-64 box that will >> run on a 32 bit machine. But I can't make it work.
>> I'm using SuSE 10.3 on a "Intel(R) Core(TM)2 CPU 4400 @ >> 2.00GHz stepping 02".
>> The gcc man page says:
>> -march=cpu-type >> Generate instructions for the machine type cpu-type. The choices for >> cpu- >> type are the same as for -mtune. Moreover, specifying >> -march=cpu-type implies -mtune=cpu-type.
>> Trying -march=i386 gives:
>> cc -g -I/home/mellman/src/ulib -o cross.o -march=i386 cross.c >> cross.c:1: error: CPU you selected does not support x86-64 instruction >> set >> cross.c:1: error: CPU you selected does not support x86-64 instruction >> set
>> Right. That's the point...
>> And -march=i686 gives:
>> cc -g -I/home/mellman/src/ulib -o cross.o -march=i686 cross.c >> cross.c:1: error: CPU you selected does not support x86-64 instruction >> set
>> (just once this time)
>> On a lark (because I don't find an explanation in the man page of what >> the difference with -march is), I tried -m32:
>> Here I get:
>> cc -g -I/home/mellman/src/ulib -o cross.o -m32 cross.c In file >> included from /usr/include/features.h:345, >> from /usr/include/stdio.h:28, >> from cross.c:1: >> /usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or >> directory
>> stubs-32.h is not on my system, and I can't find it on SuSE's site >> either.
>> I find almost nothing about this when googling. WRT stubs-32.h, the >> only thing I can find says to use different libraries (!). The >> response is always that that didn't help.
>> It would seem that this is a pretty common requirement - I have a 64 >> bit box at home and want to distribute my programs generally (like to >> my virtual server, which only has 32 bits). The lack of general >> interest here must indicate that I'm completely on the wrong track >> somehow...
>> Any ideas are appreciated...
> install glibc-devel-32bit
> regards, > lajos
Thank you. That worked. Actually, I got lost in the whirl of glibc- devel and glibc-32bit and missed that there was also a glibc-devel-32bit.
Now, is there an equally easy way to do the same thing for sparc? The last time I delved into that, it seemed like I'd have to build a special version of gcc ...
On Wed, 26 Mar 2008 14:45:02 +0000, Charles T Smith wrote: > On Wed, 26 Mar 2008 15:07:45 +0100, FÖLDY Lajos wrote:
>> On Wed, 26 Mar 2008, Charles T Smith wrote:
>>> Hi.
>>> In reading the gcc man page, and information from, say, AMD, I get the >>> impression that gcc can generate executables on an x86-64 box that >>> will run on a 32 bit machine. But I can't make it work.
>>> I'm using SuSE 10.3 on a "Intel(R) Core(TM)2 CPU 4400 @ >>> 2.00GHz stepping 02".
>>> The gcc man page says:
>>> -march=cpu-type >>> Generate instructions for the machine type cpu-type. The choices >>> for >>> cpu- >>> type are the same as for -mtune. Moreover, specifying >>> -march=cpu-type implies -mtune=cpu-type.
>>> Trying -march=i386 gives:
>>> cc -g -I/home/mellman/src/ulib -o cross.o -march=i386 cross.c >>> cross.c:1: error: CPU you selected does not support x86-64 >>> instruction >>> set >>> cross.c:1: error: CPU you selected does not support x86-64 >>> instruction >>> set
>>> Right. That's the point...
>>> And -march=i686 gives:
>>> cc -g -I/home/mellman/src/ulib -o cross.o -march=i686 cross.c >>> cross.c:1: error: CPU you selected does not support x86-64 >>> instruction >>> set
>>> (just once this time)
>>> On a lark (because I don't find an explanation in the man page of what >>> the difference with -march is), I tried -m32:
>>> Here I get:
>>> cc -g -I/home/mellman/src/ulib -o cross.o -m32 cross.c In file >>> included from /usr/include/features.h:345, >>> from /usr/include/stdio.h:28, >>> from cross.c:1: >>> /usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or >>> directory
>>> stubs-32.h is not on my system, and I can't find it on SuSE's site >>> either.
>>> I find almost nothing about this when googling. WRT stubs-32.h, the >>> only thing I can find says to use different libraries (!). The >>> response is always that that didn't help.
>>> It would seem that this is a pretty common requirement - I have a 64 >>> bit box at home and want to distribute my programs generally (like to >>> my virtual server, which only has 32 bits). The lack of general >>> interest here must indicate that I'm completely on the wrong track >>> somehow...
>>> Any ideas are appreciated...
>> install glibc-devel-32bit
>> regards, >> lajos
> Thank you. That worked. Actually, I got lost in the whirl of glibc- > devel and glibc-32bit and missed that there was also a > glibc-devel-32bit.
> Now, is there an equally easy way to do the same thing for sparc? The > last time I delved into that, it seemed like I'd have to build a special > version of gcc ...
Unfortunately, linking failed. For example, here I successfully compiled the .c file to a .o and then put the .o on my i686 machine and tried to link it:
$ cc -g -I/home/mellman/src/ulib -o cross.o -march=i386 -m32 cross.c $ file cross.o cross.o: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.4, dynamically linked (uses shared libs), not stripped
[ scp and switch to remote ]
$ cc -o cross cross.o cross.o(.text+0x0): In function `_start': : multiple definition of `_start' /usr/lib/gcc-lib/i586-suse-linux/3.3.5/../../../crt1.o(.text+0x0):../ sysdeps/i386/elf/start.S:65: first defined here cross.o(.rodata+0x0): multiple definition of `_fp_hw' /usr/lib/gcc-lib/i586-suse-linux/3.3.5/../../../crt1.o(.rodata+0x0):../ sysdeps/i386/elf/start.S:65: first defined here cross.o(.fini+0x0): In function `_fini': /usr/src/packages/BUILD/glibc-2.6.1/cc-nptl/csu/crti.S:41: multiple definition of `_fini' /usr/lib/gcc-lib/i586-suse-linux/3.3.5/../../../crti.o(.fini+0x0):/usr/ src/packages/BUILD/glibc-2.3/cc/csu/crti.S:12: first defined here cross.o(.rodata+0x4): multiple definition of `_IO_stdin_used' /usr/lib/gcc-lib/i586-suse-linux/3.3.5/../../../crt1.o(.rodata+0x4):../ sysdeps/i386/elf/start.S:71: first defined here cross.o(.data+0x0): In function `__data_start': : multiple definition of `__data_start' /usr/lib/gcc-lib/i586-suse-linux/3.3.5/../../../crt1.o(.data+0x0):../ sysdeps/i386/elf/start.S:65: first defined here cross.o(.data+0x4): In function `__data_start': : multiple definition of `__dso_handle' /usr/lib/gcc-lib/i586-suse-linux/3.3.5/crtbegin.o(.data+0x0): first defined here cross.o(.init+0x0): In function `_init': /usr/src/packages/BUILD/glibc-2.6.1/cc-nptl/csu/crti.S:15: multiple definition of `_init' /usr/lib/gcc-lib/i586-suse-linux/3.3.5/../../../crti.o(.init+0x0):/usr/ src/packages/BUILD/glibc-2.3/cc/csu/crti.S: first defined here collect2: ld returned 1 exit status
Here's trying to link it on the 64bit box:
cc -g -I/home/mellman/src/ulib -o cross -march=i686 -m32 cross.o cross.o: In function `_start': (.text+0x0): multiple definition of `_start' /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../lib/crt1.o:(.text +0x0): first defined here cross.o:(.rodata+0x0): multiple definition of `_fp_hw' /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../lib/crt1.o:(.rodata +0x0): first defined here cross.o: In function `_fini': /usr/src/packages/BUILD/glibc-2.6.1/cc-nptl/csu/crti.S:41: multiple definition of `_fini' /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../lib/crti.o:/usr/src/ packages/BUILD/glibc-2.6.1/cc-nptl/csu/crti.S:41: first defined here cross.o:(.rodata+0x4): multiple definition of `_IO_stdin_used' /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../lib/crt1.o: (.rodata.cst4+0x0): first defined here cross.o: In function `__data_start': (.data+0x0): multiple definition of `__data_start' /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../lib/crt1.o:(.data +0x0): first defined here cross.o: In function `__data_start': (.data+0x4): multiple definition of `__dso_handle' /usr/lib64/gcc/x86_64-suse-linux/4.2.1/32/crtbegin.o:(.data+0x0): first defined here cross.o: In function `_init': /usr/src/packages/BUILD/glibc-2.6.1/cc-nptl/csu/crti.S:15: multiple definition of `_init' /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../lib/crti.o:/usr/src/ packages/BUILD/glibc-2.6.1/cc-nptl/csu/crti.S:15: first defined here collect2: ld returned 1 exit status make: *** [cross] Error 1