Errors with linkers and stuff

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
rspencer
Posts: 18
Joined: Wed Feb 03, 2010 12:05 am

Errors with linkers and stuff

Post 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?
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Errors with linkers and stuff

Post 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.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
eaglexrlnk
Posts: 11
Joined: Tue Nov 08, 2011 8:30 am
Location: Ukraine

Re: Errors with linkers and stuff

Post 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
"A
computer program
does what you tell it
to do, not what you
want it to do." --
Greer's Third Law
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: Errors with linkers and stuff

Post 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.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Errors with linkers and stuff

Post 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
Post Reply