Page 1 of 1

Errors with linkers and stuff

Posted: Thu Dec 22, 2011 10:28 am
by rspencer
Hi.

I am having a problem following a tutorial (http://www.osdever.net/tutorials/view/w ... e-c-kernel). I have done everything and understand it all. My problem is that I am using Widows (MinGW) and my ld gives error:

Code: Select all

ld: cannot perform PE operations on non PE output file '..\filesystem\kernel.bin'.
The relevant compilation code is:

Code: Select all

"C:\Program files\nasm\nasm.exe" -f elf32 kernel.asm -o ..\filesystem\kernel.o
gcc _kernel.c -c -o ..\filesystem\kn.o
ld -T link.ld ..\filesystem\kernel.o ..\filesystem\kn.o -o ..\filesystem\kernel.bin 
I have made some minor edits to the code given in the tutorial (my own cls and putstr in 32bit asm) but the main part is similar (with _kmain etc). I believe it is a problem with the MinGW ld. I found another topic with a similar problem. The fix for this however, relied on cygwin. Can anybody help?

Re: Errors with linkers and stuff

Posted: Thu Dec 22, 2011 12:00 pm
by xenos
The best solution for this problem is the same both on CygWin and MinGW - use a GCC Cross-Compiler.

Another option is to completely switch from ELF to PE format. Some people in this forum have written PE kernels, but most OS devers prefer ELF.

Re: Errors with linkers and stuff

Posted: Fri Dec 23, 2011 2:03 am
by eaglexrlnk
You can link your kernel as PE binary and then convert it to ELF with the objcopy utility:

Code: Select all

objcopy -O elf32-i386 kernel.bin

Re: Errors with linkers and stuff

Posted: Fri Dec 23, 2011 6:30 am
by gravaera
eaglexrlnk wrote:You can link your kernel as PE binary and then convert it to ELF with the objcopy utility:

Code: Select all

objcopy -O elf32-i386 kernel.bin
Congratulations on completely dismantling what Xenos was trying to do for the OP.

Re: Errors with linkers and stuff

Posted: Fri Dec 23, 2011 1:28 pm
by AJ
Hi,
eaglexrlnk wrote:You can link your kernel as PE binary and then convert it to ELF with the objcopy utility:
This seems a path to future problems. @OP: The tutorials you find on our wiki will generally assume the Cross Compiler option (as XenOS suggested). We'll also be able to help you much more with future problems if you're using the "standard" toolchain detailed in the wiki.

Cheers,
Adam