NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: rostomdz 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 .
-
when i link the objs files the linker tells me that the (nasm) object file format doesn't recognized
Try ELF (-f elf64) instead.
-
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...
-
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
-
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.