2

Trying to compile a C++ kernel project with MinGW & NASM (formerly DJGPP & NASM). Have actually tried Cygwin too, with the exact same results below:

  • First, just swapped out \DJGPP\bin for \MinGW\bin. Got the following link error: target coff-go32 not found.
  • Swapped target to elf32-i386, and got cannot perform PE operations on non PE output file 'build/kernel.elf' This was a bit of a weird error, since to my knowledge I'm not doing any 'PE operations'.
  • Changed target again, to pe-i386, got a new error build/Common.o:Common.cc:(.text+0x2a): undefined reference to 'atexit'

It seems MinGW is generating atexit calls for static classes. DJGPP did not. The kernel does it's own DTOR handling during shutdown. I am aware that defining atexit would 'solve' this, but that would be more of a hack at this point, and not a longterm solution. I want rather to get MinGW compiling the existing code without any (or minimal) modifications.

Frankly, I'm not that familiar with the Windows build environment and could use any tips on what to do. The project (minus the changes listed above) compiles and boots fine under DJGPP. The difference seems to be in the way DJGGP and MinGW handle compile-time class declarations?

EDIT: Finally broke down and built a cross-compiler on Cygwin. All working now.

Unsigned
  • 9,640
  • 4
  • 43
  • 72
  • The [OSDev wiki](http://wiki.osdev.org/C_PlusPlus) might have useful info (it's an invaluable resource for x86 osdev imo). For more specific advice you should include your exact build steps (command line/ Makefile and any relevant code). – user786653 Oct 18 '11 at 16:09

1 Answers1

3

You need to build a free-standing cross compiler. This problem has been referenced many times at the OSDev Wiki to the point that most people recommend you begin writing a kernel by first creating a cross compiler.

This article will provide a step-by-step reference to building your own cross compiler. Note, in Windows, you may have to build the cross compiler using MingW or Cygwin

Earlz
  • 62,085
  • 98
  • 303
  • 499
  • 1
    The Windows build environment is crazy! :) This is the solution I ended up going with. +1 for good links. – Unsigned Oct 19 '11 at 02:33