Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

compiling for 32 bit x86 machines on a x86-64 box

123 views
Skip to first unread message

Charles T Smith

unread,
Mar 26, 2008, 6:27:09 AM3/26/08
to
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...

FÖLDY Lajos

unread,
Mar 26, 2008, 10:07:45 AM3/26/08
to

install glibc-devel-32bit

regards,
lajos

Charles T Smith

unread,
Mar 26, 2008, 10:45:02 AM3/26/08
to


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.

Note for others: you will then have to install

gcc42-32bit-4.2.1_20070724-17.x86_64.rpm
libgomp (for 32 bits)
libmudflap (for 32 bits)


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 ...

Charles T Smith

unread,
Mar 26, 2008, 1:32:58 PM3/26/08
to


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

Charles T Smith

unread,
Mar 26, 2008, 2:57:08 PM3/26/08
to


Okay, silly me. I left out the -c on the initial compile.

Paul Pluzhnikov

unread,
Mar 27, 2008, 12:17:28 AM3/27/08
to
Charles T Smith <cts.p...@yahoo.com> writes:

> Now, is there an equally easy way to do the same thing for sparc?

All recent versions of gcc, when configured and built on 64-bit
Solaris/SPARC, support '-m32' (default) and '-m64' out of the box.

Or is your question about Linux/SPARC?

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.

cocobear

unread,
May 22, 2008, 5:01:00 AM5/22/08
to
On 3月27日, 下午12时17分, Paul Pluzhnikov <ppluzhnikov-...@gmail.com> wrote:


Where can I find glibc-devel-32bit-2.8, I can only find glibc-
devel-32bit-2.5, but my glibc-devel is 2.8 :glibc-devel-2.8-3.x86_64
.

I use fedora 9

Paul Pluzhnikov

unread,
May 22, 2008, 11:23:03 AM5/22/08
to
cocobear <cocob...@gmail.com> writes:

Please don't follow-up to a completely unrelated message.
Start a new thread, with a new subject instead.

You are also completely off-topic in this group. Next time please
use one of the *linux* groups for linux-specific questions.

> Where can I find glibc-devel-32bit-2.8, I can only find glibc-
> devel-32bit-2.5, but my glibc-devel is 2.8 :glibc-devel-2.8-3.x86_64

Go to http://rpm.pbone.net/, type glibc-devel-2.8-3.i386 into the search box.

0 new messages