views:

138

answers:

3

I've just bought a new laptop for me on the travel, then on my free time, I've started to test MinGW on it by trying to compile my own OS that is written in C++, then I've created all the files needed and the kernel.cpp:

extern "C" void _main(struct multiboot_data* mbd, unsigned int magic);

void _main( struct multiboot_data* mbd, unsigned int magic )
{
   char * boot_loader_name =(char*) ((long*)mbd)[16];

   /* Print a letter to screen to see everything is working: */
   unsigned char *videoram = (unsigned char *) 0xb8000;
   videoram[0] = 65; /* character 'A' */
   videoram[1] = 0x07; /* forground, background color. */
}

And tried to compile it with g++

G:> g++ -o C:\kernel.o -c kernel.cpp -Wall -Wextra -Werror -nostdlib -nostartfiles -nodefaultlibs
kernel.cpp: In function `void _main(multiboot_data*, unsigned int)':
kernel.cpp:8: warning: unused variable 'boot_loader_name'
kernel.cpp: At global scope:
kernel.cpp:4: warning: unused parameter 'magic'

G:>

But it don't create any binary file at C:/>.

What can I do?

+1  A: 

Did you try creating the .o file in a local directory first? What result did you get?

Eli Bendersky
Yeah, and I still got nothing.
Nathan Campos
@Nathan: that's strange. Try to compile an empty `main` into an executable, does mingw create it ?
Eli Bendersky
@Nathan: and then with the same commandline invocation your .cpp file creates nothing? no new files at all?
Eli Bendersky
@Eli: If I do a Hello World(using `cout`, `#include`...) it compiles nice, but if I try to compile my simple kernel, I don't create anything.
Nathan Campos
@Nathan: could it be because your kernel doesn't have a `main` function?
Eli Bendersky
I think no, because when I was compiling it on my Linux machine(at my home) it compiles nice.
Nathan Campos
Also, trying to compile a empty `_main` don't create a object file.
Nathan Campos
+1  A: 

C:\ is usually blocked for writing on Vista and 7, since it's considered a very sensitive location, and you have to run as administrator to be allowed to do that (as in, explicitly launching the command prompt or g++ with admin rights). The same should apply if you're running on a "regular" (non-admin) user account, even in XP.

Perhaps that's what's happening to you?

Michael Madsen
I've changed for `G:` and I still got nothing.
Nathan Campos
+3  A: 

It doesn't create the file because you have -Werror enabled. The warnings you're getting about unused variables are counting as errors, so compilation gets aborted. Just comment them out for the moment:

void _main( struct multiboot_data* mbd, unsigned int /* magic */ )
{
    // char * boot_loader_name =(char*) ((long*)mbd)[16];
    // ...
}

And it should build fine. Also, shouldn't _main() be declared as just main() and then allowed to be "mangled" into _main() by the compiler? Edit: You probably also want to be using -c to skip the linking phase, assuming you just want the object files.

Jon Purdy
I'm developing a OS, then using `main` is totally wrong.
Nathan Campos
Ah, right, `extern "C"` takes care of that. Silly rabbit. Plus it's been a while since I looked at the wiki.
Jon Purdy