Page 1 of 2

C++ OS Programming

Posted: Sun Oct 22, 2006 12:33 am
by Cmaranec
Do you have a knowledge of OS programming in C++(under Windows)?? Which compilers do you use and which commands do you use for compile. Please, place here a link to download them. thx

PS: Please excuse my formulation, because i am czechian.

Re: C++ OS Programming

Posted: Sun Oct 22, 2006 12:59 am
by Mike
I'm writing my OS in C++ in Microsoft Visual Studio 2005. (With FASM for the bootloader and protected-mode-entry stub) Check out "Visual C" on the wiki which details some of the issues I faced.

> PS: Please excuse my formulation, because i am czechian.

Cool! I am half-Czech... but unfortunately all I know of the language are the numbers 1-10, "good day", and "beer".

Mike

Which compiler

Posted: Sun Oct 22, 2006 1:08 am
by Cmaranec
Which compilers and linkers do you use? If you use DJGPP please tell me what version. :roll:

Posted: Sun Oct 22, 2006 1:56 am
by Daedalus
DJGPP of any version seems to work fine for me.

...

Posted: Sun Oct 22, 2006 2:34 am
by Cmaranec
4 Daedalus: Which commands do you use to compile the kernel of your OS?? I am using:
@ECHO OFF

echo Kompiluji kernel...

c:\dev-cpp\bin\gcc -w -nostdlib -fno-builtin -ffreestanding -c -o kernel32.o kernel32.cpp

echo Kompiluji loader...

c:\compiler\nasm -f aout Loader.asm -o Loader.o

echo Linkuji...

c:\dev-cpp\bin\ld -o Kernel.bin Loader.o Kernel32.o

echo Proces dokoncen...

pause
And cmd.exe gave back: Loader.o: File not recognized: File format not recognized

What i do wrong?

Posted: Sun Oct 22, 2006 3:34 am
by inflater
Try this:

Code: Select all

echo Kompilujem loader...

c:\compiler\nasm -f bin Loader.asm -o Loader.o

echo Linkujem...

c:\dev-cpp\bin\ld -oformat BINARY -o Kernel.bin Loader.o Kernel32.o
I am full Slovak, full Czech, "sort of a English'er" and "Ich spreche auch Deutsch, bitte !" :D

Slovensko pozdravuje Česko !

inflater

eh

Posted: Sun Oct 22, 2006 3:57 am
by Cmaranec
Now, it throw
Kompiluji kernel...
Kompiluji loader...
Loader.asm:6: error: binary output format does not support external references
Linkuji...
c:\dev-cpp\bin\ld: target BINARY not found
Proces dokoncen...
Pokračujte stisknutím libovolné klávesy...

Česko zdraví Slovensko! :D

Posted: Sun Oct 22, 2006 7:56 am
by Combuster
Uner windows you have three standard choices: GCC (cross-compiler, perhaps) MSVC and Watcom
I personally use the GCC cross-compiler, but you should check the wiki on how to use each of them, since the compilers, linkers and assemblers are generally not interoperable by default.

On another note, nasm generates binary output in this construction, not object files.
you should use

Code: Select all

nasm -f elf -o loader.o loader.asm
change "elf" with a different format to change the output. you may want to try "coff" if you use something else than gnu ld
(try "nasm -hf" to see what nasm can give you)

Something similar goes for the ld, where the parameter should probably read "--otarget binary", case sensitive.

errr

Posted: Sun Oct 22, 2006 8:24 am
by Cmaranec
In linking procces is something wrong:
Kompiluji kernel...
Kompiluji loader...
Linkuji...
Kernel32.o(.text+0xd):kernel32.cpp: undefined reference to `std::string::size()
const'
Kernel32.o(.text+0x60):kernel32.cpp: undefined reference to `std::string::operat
or[](unsigned int) const'
Kernel32.o(.text+0x9f):kernel32.cpp: undefined reference to `std::string::operat
or[](unsigned int) const'
Kernel32.o(.text+0xce):kernel32.cpp: undefined reference to `std::string::operat
or[](unsigned int) const'
Kernel32.o(.text+0x121):kernel32.cpp: undefined reference to `_alloca'
Kernel32.o(.text+0x126):kernel32.cpp: undefined reference to `__main'
Kernel32.o(.text+0x135):kernel32.cpp: undefined reference to `std::cout'
Kernel32.o(.text+0x13a):kernel32.cpp: undefined reference to `std::basic_ostream
<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::
basic_ostream<char, std::char_traits<char> >&, char const*)'
Kernel32.o(.text+0x163):kernel32.cpp: undefined reference to `std::ios_base::Ini
t::Init()'
Kernel32.o(.text+0x17e):kernel32.cpp: undefined reference to `std::ios_base::Ini
t::~Init()'
Proces dokoncen...
Pokračujte stisknutím libovolné klávesy...
I use "nasm -f elf Loader.asm -o Loader.o".
Loader.o is succesfully compiled and linked, but in Kernel32.o is bug...

linker script

Posted: Sun Oct 22, 2006 8:30 am
by Cmaranec
I have a linker script from wiki. When i used the old classic linker script, it wrote "PE operations on non PE file". I use script from wiki.

Posted: Sun Oct 22, 2006 9:14 am
by bluecode
You have to build a crosscompiler under windows if you want to use the elf file format for your os. There is also an article on the wiki about that.

heh...

Posted: Sun Oct 22, 2006 10:01 am
by Cmaranec
Can you (or anybody other) send me an example of your simple OS with .BAT file??? It will be better.

Posted: Sun Oct 22, 2006 11:28 am
by Pype.Clicker
it sounds like you're missing the string class and COUT stuff to have your kernel running. You know you cannot simply reuse the standard library of your hosting OS, don't you?

yes

Posted: Sun Oct 22, 2006 12:15 pm
by Cmaranec
Yes, i know. How i insert this classes to my kernel?

Posted: Sun Oct 22, 2006 1:52 pm
by bluecode
Make your own std::string class or port an existing C++ library. I don't recommend the later one at your stage, it's just to much C++ runtime required (exception handling, RTTI).