How to compile 32bit code

Latest response

I am using RHEL 7.0

I have downloaded latest version of Eclipse cdt.

I try to compile some 32bit c++ code.
I have installed the "*-devel.i686"-packets

I have set "-m32" at the compiler options and set -melf_i386

During linking build system tries to link against libraries at /usr/lib/gcc/x86_64-redhat-linux

I have tried to set the variables "LD_LIBRARY_PATH" and "LIBRARY_PATH" under "envirement" both to "/usr/lib" without any effect

I have added "-L/usr/lib" and "-L/lib" to the linker.
Now I still have a problem with crtl.o, crti.o, crtbegin.o, crtend.o and crtn.o
I see that eclipse try to link against versions in "/lib/../lib64"

Is there any other general way to set the libraries to 32bit?
Do I have to install any additional packets?

I was able to reproduce the same behaviour under command line:

dirk1.o and dirk2.o are compiled with "-m32"

g++ -Xlinker -melf_i386 -Xlinker -L/usr/lib -Xlinker -L/lib -Xlinker -L/usr/lib/gcc/x86_64-redhat-linux/4.8.2/32 -L/usr/lib -L/lib dirk1.o dirk2.o -o dirk -L/usr/lib/gcc/x86_64-redhat-linux/4.8.2/32

/bin/ld: i386:x86-64 architecture of input file /usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../lib64/crt1.o' is incompatible with i386 output
/bin/ld: i386:x86-64 architecture of input file
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../lib64/crti.o' is incompatible with i386 output
/bin/ld: i386:x86-64 architecture of input file /usr/lib/gcc/x86_64-redhat-linux/4.8.2/crtbegin.o' is incompatible with i386 output
/bin/ld: i386:x86-64 architecture of input file
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/crtend.o' is incompatible with i386 output
/bin/ld: i386:x86-64 architecture of input file `/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../lib64/crtn.o' is incompatible with i386 output
/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../lib64/crt1.o: file class ELFCLASS64 incompatible with ELFCLASS32
/bin/ld: final link failed: File in wrong format
collect2: Fehler: ld gab 1 als Ende-Status zurück

Any ideas are welcome.

Dirk

Responses

I was able to reproduce the same behaviour under command line:

dirk1.o and dirk2.o are compiled with "-m32"

g++ -Xlinker -melf_i386 -Xlinker -L/usr/lib -Xlinker -L/lib -Xlinker -L/usr/lib/gcc/x86_64-redhat-linux/4.8.2/32 -L/usr/lib -L/lib dirk1.o dirk2.o -o dirk -L/usr/lib/gcc/x86_64-redhat-linux/4.8.2/32

/bin/ld: i386:x86-64 architecture of input file /usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../lib64/crt1.o' is incompatible with i386 output
/bin/ld: i386:x86-64 architecture of input file
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../lib64/crti.o' is incompatible with i386 output
/bin/ld: i386:x86-64 architecture of input file /usr/lib/gcc/x86_64-redhat-linux/4.8.2/crtbegin.o' is incompatible with i386 output
/bin/ld: i386:x86-64 architecture of input file
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/crtend.o' is incompatible with i386 output
/bin/ld: i386:x86-64 architecture of input file `/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../lib64/crtn.o' is incompatible with i386 output
/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../lib64/crt1.o: file class ELFCLASS64 incompatible with ELFCLASS32
/bin/ld: final link failed: File in wrong format
collect2: Fehler: ld gab 1 als Ende-Status zurück

Does adding:

-Xlinker --verbose

Give any more insight? Hoping it might confirm that the options you are specifying are making it through to ld correctly.

Dirk,

Maybe a silly question, but have you installed the 32 bits gcc compiler set?

Kind regards,

Jan Gerrit Kootstra

Hi Dirk,

Found on my rhel7 test server the 32 bits rpms for gcc do not seem to exist any more.
The gcc 64-bits compiler with -m32 switch is the only way to go.
Can you share the source code you try to compile, or is it an in-house code that cannot be revealed?

Kind regards,

Jan Gerrit Kootstra

I found out that I had to add a "-m32" also to the linker-call
"g++ -m32 -Xlinker -melf_i386 d1.o d2.o -o prog" did it.

In this case it automatically takes the right library pathes

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.