Author Topic: 32bit compile/link under 64bit linux  (Read 24671 times)

Offline xdcx

  • Jr. Member
  • *
  • Posts: 12
32bit compile/link under 64bit linux
« on: December 02, 2012, 07:54:31 AM »
edit: just neededed to
Code: [Select]
%include "/usr/local/include/asm_io.inc"
where is the nasm directory in ubuntu, like windows?

why cant i compile, link and run 32bit assembly?
Code: [Select]
i386 architecture of input file `asm1.o' is incompatible with i386:x86-64 output
« Last Edit: December 02, 2012, 06:55:44 PM by xdcx »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: include directory
« Reply #1 on: December 02, 2012, 09:18:53 AM »
Well... I'm not aware of any "Nasm include directory" or any "Nasm directory" (Windows may have one) except for the source directory if you built Nasm from source (.../nasm-x.y where x and y are version number). You can find Nasm itself (and ndisasm) by doing "which nasm" - probably /usr/bin or /usr/local/bin. There are no include files that "come with" Nasm.

"asm_io.inc" sounds like one of Dr. Paul Carter's files, although it could be anything. As I recall (it was a long time ago I downloaded it), his examples untarred into a single directory - that may have changed. Where did you put it? If you've lost track, "locate asm_io.inc" should find it. /usr/local/include might be a sensible place to put this stuff, but it isn't automatic (unless Ubuntu - apt-get or so - does something with... whatever you downloaded). ASSuming you've got Dr. Carter's stuff, besides "asm_io.inc" you'll need to link against "asm_io.o", which you may have to build from "asm_io.asm". You'll also need to find "driver.c". Be sure you got the examples package intended for Linux! http://www.drpaulcarter.com/pcasm I think...

As an alternative to putting the full path in your source...
Code: [Select]
%include "/home/fbk/oldsrc/pctut/asm_io.inc"
(elsewhere on your system, no doubt), you can tell Nasm where to look by including the "-I" switch on the command line...
Code: [Select]
nasm -f elf32 first.asm -I /home/fbk/oldsrc/pcasm/
(or wherever) Note that the trailing '/' is required! We have had several contributions eliminating this requirement, but they have all been rejected. RTFM: http://www.nasm.us/xdoc/2.10.05/html/nasmdoc2.html#section-2.1.16 under "really perverse" to see why. :)

You may, if you wish, set an environment variable NASMENV which will be appended to the command line. You can put one or more search directories ("-i" or "-I") here, if you wish. (RTFM if you need spaces in your pathnames) If you want to make /usr/local/include/ your "nasm include directory", this might be a good place to do it.

If I've misunderstood which "asm_io.inc" you're looking for, we can discuss it further, but I'm pretty sure you didn't get it "with Nasm".

Best,
Frank


Offline xdcx

  • Jr. Member
  • *
  • Posts: 12
Re: include directory
« Reply #2 on: December 02, 2012, 06:09:04 PM »
im on 64bit linux, but im working with 32 bit only, and yes i am using pcasm book

Code: [Select]
nasm -f elf32 asm1.asm
gcc -m32 -c /usr/include/driver.c

Code: [Select]
xdc@ubuntu:~$ gcc -m32 -o asm1.asm driver.o asm1.o /home/xdc/pcasm/asm_io.o

/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status

without -m32
Code: [Select]
xdc@ubuntu:~$ gcc -o asm1.asm driver.o asm1.o /home/xdc/pcasm/asm_io.o

/usr/bin/ld: i386 architecture of input file `driver.o' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `asm1.o' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `/home/xdc/pcasm/asm_io.o' is incompatible with i386:x86-64 output
/usr/bin/ld: driver.o: file class ELFCLASS32 incompatible with ELFCLASS64
/usr/bin/ld: final link failed: File in wrong format
collect2: error: ld returned 1 exit status
« Last Edit: December 02, 2012, 06:13:28 PM by xdcx »

Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 429
  • Country: us
Re: 32bit compile/link under 64bit linux
« Reply #3 on: December 02, 2012, 08:13:54 PM »
I'm pretty sure your linker stage should be:
Code: [Select]
gcc -m32 -lc -o PROGNAMEHERE asm1.o driver.o asm1.o /home/xdc/pcasm/asm_io.o
The crt1.o contains the C library startup code which should be found with the -lc switch.
Double check your asm source to make sure you didn't just hose it with your last gcc command.

Offline xdcx

  • Jr. Member
  • *
  • Posts: 12
Re: 32bit compile/link under 64bit linux
« Reply #4 on: December 03, 2012, 12:09:00 AM »
fixed

Code: [Select]
sudo apt-get install gcc-multilib
Code: [Select]
nasm -f elf32 asm1.asm
gcc -m32 -lc -o asm1 asm1.o /home/xdc/pcasm/driver.c /home/xdc/pcasm/asm_io.o

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: 32bit compile/link under 64bit linux
« Reply #5 on: December 03, 2012, 01:07:03 AM »
There ya go! I remembered that there was an issue with Ubuntu (an African word meaning "one ring to rule them all" /joke) not coming with the 32-bit libraries, and I remembered that there was a package that fixed it. "gcc-multilib", "gcc-multilib", "gcc-multilib"... I'll try to remember that. I'm sure you're not the last person who will run into it. Thanks!

Best,
Frank