hi , I just using 64 bit linux with my powerfull desktop computer.

and I use Scientific linux as the destro,I use the RPM binary package to install
gcc. and I using nasm also.

I write simple example program in a nasm assembly (free) book.And the author
gives some library and include file for the assembly named 'asm_io.inc' and
'asm_io.o' so , they are linux 32 bit.

So what I need is to compile this to i386 targert. But my gcc doesn't allow this.
and I force the gcc linker using -m elf_i386 option. But it doesn't seems works.

[root@ZXDSL831CII ch01]# gcc -o first driver.o first.o  asm_io.o 
/usr/bin/ld: warning: i386 architecture of input file `first.o' is incompatible with i386:x86-64 output
/usr/bin/ld: warning: i386 architecture of input file `asm_io.o' is incompatible with i386:x86-64 output
driver.o: In function `main':
driver.c:(.text+0xe): undefined reference to `asm_main'
collect2: ld returned 1 exit status
[root@ZXDSL831CII ch01]# nasm  -f aout first.asm
[root@ZXDSL831CII ch01]# gcc -o first driver.o first.o  asm_io.o 
/usr/bin/ld: warning: i386 architecture of input file `first.o' is incompatible with i386:x86-64 output
/usr/bin/ld: warning: i386 architecture of input file `asm_io.o' is incompatible with i386:x86-64 output
[root@ZXDSL831CII ch01]# ./first
Illegal instruction  << see how much foolish is this gcc !
[root@ZXDSL831CII ch01]# gcc -m i386 -o first driver.o first.o  asm_io.o 
/usr/bin/ld: unrecognised emulation mode: i386
Supported emulations: elf_x86_64 elf_i386 i386linux
collect2: ld returned 1 exit status
[root@ZXDSL831CII ch01]# gcc -m i386linux -o first driver.o first.o  asm_io.o 
/usr/bin/ld: unrecognized option '--eh-frame-hdr'
/usr/bin/ld: use the --help option for usage information
collect2: ld returned 1 exit status
[root@ZXDSL831CII ch01]# gcc -m elf_i386 -o first driver.o first.o  asm_io.o 
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.1.2/libgcc.a when searching for -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.1.2/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
collect2: ld returned 1 exit status
[root@ZXDSL831CII ch01]#

and I wonder how the 'first' is built without the error at first time.

yes it was a 64 bit executable file.

[root@ZXDSL831CII ch01]# file first
first: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped
[root@ZXDSL831CII ch01]#

see ,

any ideas ! I mean without installing or building back the gcc from the scratch ?

Anyway looks like I have to download the source tarball gcc and change the configurations to i386 and build it back. Please give me some advice , I mean
the configure options.

and I need to keep the 64-bit gcc also , but need the 32 bit one also , please
give me some nice idea here.

--Thanks in advance--

The early attempts you've attemted to compile with the wrong architectural targets for your sources, it even warned you about that, obviously that's going to have issues.

The final attempt you've set the correct architecture but the version of libgcc it has found is incompatible (as the errors state). Those libraries are likely 64bit libraries. So is gcc looking in the correct place for the correct version of libgcc? Do you even have the 32bit libs installed? Obviously you cannot link 32bit targets to 64bit libs.

and I wonder how the 'first' is built without the error at first time.

Because - given the design of gcc - this is not illegal, it's probably not what you wanted and in that case it won't work but there are times when it is justifiable to do that. Hence it is a warning, not an error. Which is why you get an 'Illegal instruction' error when you try to run it.

oky , I think you got a point ,
Then I will try to override the library searching path to lib32 directory.

oky , I think you got a point ,
Then I will try to override the library searching path to lib32 directory.

If you have the correct libraries in there it should work.

I thinks I have dig enough threads right now.Need some help now.

can somebody give me some idea about how to install 32 bit libraries .
is there is a package to download ? or something article to read is very
usefull.

AFAIK there is a libgcc rpm that you could install - youll have to have a browse of the repo. Though the best option is to find the appropriate option to build the required 32bit versions of libraries when building gcc yourself.

@Stinomus Thank you. I installed libc6-dev-i386 (Ubuntu 64 bit) and it did the trick. I already had installed ia32-libs which did not solve above problem. After installing libc6-dev-i386 package, examples from pcasm-book.pdf executes. However I made some changes(don't know if it is required) to the make file(Makefile) of linux-ex.zip.

AS=nasm
ASFLAGS= -f elf32
CFLAGS=
CC=gcc -m32
CXX=g++ -m32
CXXFLAGS=

There are one or two examples that might not compile, but most do. And they are perfect 32-bit binary

$ file first
first: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.