Jump to content

Linker error

- - - - -

  • Please log in to reply
5 replies to this topic

#1
DarkLordofthePenguins

DarkLordofthePenguins

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 409 posts
I tried linking two x86 Assembly object files with gcc. The object files were created with NASM. I got the following error message:


$ gcc -o first asm_io.o first.o

/usr/bin/ld: i386 architecture of input file `asm_io.o' is incompatible with i386:x86-64 output

/usr/bin/ld: i386 architecture of input file `first.o' is incompatible with i386:x86-64 output

/usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/crt1.o: In function `_start':

(.text+0x20): undefined reference to `main'

collect2: ld returned 1 exit status


What is the problem here? I assembled first.o using NASM on an x86-64 machine. My computer has an AMD64 processor, which uses x86-64. How can I get it to assemble into an x86-64 format? My NASM docs don't address this issue.
Programming is a journey, not a destination.

#2
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
What output format did you use with NASM. Assuming you are using Linux (it looks like it) you probably want elf64 output. Plus, I'm not sure, but it looks like you named your main function in your assembly code "main" and it should be "_main".
Latinamne loqueris?

#3
DarkLordofthePenguins

DarkLordofthePenguins

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 409 posts
I've tried using ELF64. It says "such and such instruction not supported in 64-bit mode" referring mainly to the macros defined in the include file.

Okay, here are the files I have, because this is convoluted as fuçk:

first.s - the file I wrote, which includes asm_io.inc
asm_io.inc - the include file, with external references to calls defined somewhere else
asm_io.asm - defines the calls referenced by asm_io.inc in terms of C library functions
asm_io.o - prebuilt object file, apparently containing the 32-bit include code for the calls

I have tried rebuilding asm_io.o by assembling both asm_io.inc and asm_io.asm into object files. When I did a diff on them, it said that both of them differ from asm_io.o. So to rebuild asm_io.o in 64 bits I would need to know what file it was created from. The three I listed are the only ones with "asm_io" in their filenames so I have no idea what the hell that would be. Unfortunately, the tutorial does not contain any pointers.

I think I'm just going to try a different tutorial.
Programming is a journey, not a destination.

#4
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
Possibly the such and such instructions are memory-addressing and they are attempting to address the memory using 32 bit pointers. But yes, a different tutorial is a good idea. You should use one for x86-64 :)
Latinamne loqueris?

#5
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
@DarkLordOfThePenguins: Did you just say a bad word?

#6
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Some x86 instructions were remapped to different functionalities in x86-64, so things like inc and dec on registers is no longer valid. What instructions does it complain about?
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users