Author Topic: Problem with linking obj files !!  (Read 15077 times)

Offline rostomdz

  • Jr. Member
  • *
  • Posts: 2
Problem with linking obj files !!
« on: May 28, 2011, 10:18:57 AM »
good morning every one  :D

i'm trying to write a simple kernel using gcc 64bit for C and C++, and nasm for assembly.
well, i tried to compile a simple code for the kernel , but the problem is in linking!!!!
when i link the objs files the linker tells me that the (nasm) object file format doesn't recognized :


C:\nasm\Nouveaudossier>gcc -c video.cpp -ffreestanding -nostdlib -fno-builtin -fno-rtti -fno-exceptions -o Video.obj

C:\nasm\Nouveaudossier>gcc -c kernel.cpp -ffreestanding -nostdlib -fno-builtin -fno-rtti -fno-exceptions -o Kernel.obj

C:\nasm\Nouveaudossier>nasm -f aout k_init.asm -o k_init.obj

C:\nasm\Nouveaudossier>ld -T Link.ld -o KRNL.BIN Kernel.obj Video.obj K_init.obj
K_init.obj: file not recognized: File format not recognized

C:\nasm\Nouveaudossier>pause
Appuyez sur une touche pour continuer...

K_init.obj: file not recognized: File format not recognized     :-X

i think the problem is that nasm that i use is 32bit and the linker and gcc compiler is 64bit, so form where can i download the nasm 64bit , help me please.

sorry for my English  ;D .     

Offline Keith Kanios

  • Full Member
  • **
  • Posts: 383
  • Country: us
    • Personal Homepage
Re: Problem with linking obj files !!
« Reply #1 on: May 28, 2011, 10:43:54 AM »
when i link the objs files the linker tells me that the (nasm) object file format doesn't recognized

Try ELF (-f elf64) instead.

Offline rostomdz

  • Jr. Member
  • *
  • Posts: 2
Re: Problem with linking obj files !!
« Reply #2 on: May 28, 2011, 11:14:08 AM »
thnx brother it's work  :D
the linker still doesn't work but when i invoke it form gcc, it work clearly without using the link script. i like this awesome forum. ::)


C:\nasm\Nouveaudossier>gcc -c video.cpp -ffreestanding -nostdlib -fno-builtin -fno-rtti -fno-exceptions -o Video.obj

C:\nasm\Nouveaudossier>gcc -c kernel.cpp -ffreestanding -nostdlib -fno-builtin -fno-rtti -fno-exceptions -o Kernel.obj

C:\nasm\Nouveaudossier>nasm -f elf64 k_init.asm -o k_init.obj

C:\nasm\Nouveaudossier>ld -T Link.ld -o KRNL.BIN Kernel.obj Video.obj K_init.obj
ld: cannot perform PE operations on non PE output file 'KRNL.BIN'.

C:\nasm\Nouveaudossier>gcc -o KENL.EXE Kernel.obj Video.obj K_init.obj
coooool that Done  :) :)  
C:\nasm\Nouveaudossier>pause
Appuyez sur une touche pour continuer...
« Last Edit: May 28, 2011, 11:16:00 AM by rostomdz »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Problem with linking obj files !!
« Reply #3 on: May 28, 2011, 01:47:38 PM »
The references to ".exe" and "PE operations" make me think you may want "-f win64" instead of "-f elf64". Just guessing, but try that.

Best,
Frank


Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 429
  • Country: us
Re: Problem with linking obj files !!
« Reply #4 on: May 28, 2011, 03:33:42 PM »
You mention previously that you are building a kernel.  You are doing this on a Windows machine, apparently using a MingW gcc, with nasm.  You are outputting a Windows executable ( .exe ).
You do realize that you will not be able to issue kernel-type operations unless you are running within a VM where you have also written the loader.
Finally, if the machine you are building on, and the tools you are using, are 64-bit, but you need 32-bits - try adding the command line option -m32 to gcc.
This may, or may not, help you.