C++ OS Programming

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.
Cmaranec
Member
Member
Posts: 45
Joined: Sat Oct 21, 2006 1:07 pm
Location: Czech Republic

C++ OS Programming

Post 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.
Mike
Member
Member
Posts: 25
Joined: Tue Oct 17, 2006 7:57 pm

Re: C++ OS Programming

Post 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
Cmaranec
Member
Member
Posts: 45
Joined: Sat Oct 21, 2006 1:07 pm
Location: Czech Republic

Which compiler

Post by Cmaranec »

Which compilers and linkers do you use? If you use DJGPP please tell me what version. :roll:
User avatar
Daedalus
Member
Member
Posts: 74
Joined: Sun Oct 16, 2005 11:00 pm
Location: Australia
Contact:

Post by Daedalus »

DJGPP of any version seems to work fine for me.
Cmaranec
Member
Member
Posts: 45
Joined: Sat Oct 21, 2006 1:07 pm
Location: Czech Republic

...

Post 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?
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post 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
Cmaranec
Member
Member
Posts: 45
Joined: Sat Oct 21, 2006 1:07 pm
Location: Czech Republic

eh

Post 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
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Cmaranec
Member
Member
Posts: 45
Joined: Sat Oct 21, 2006 1:07 pm
Location: Czech Republic

errr

Post 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...
Last edited by Cmaranec on Sun Oct 22, 2006 8:34 am, edited 1 time in total.
Cmaranec
Member
Member
Posts: 45
Joined: Sat Oct 21, 2006 1:07 pm
Location: Czech Republic

linker script

Post 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.
User avatar
bluecode
Member
Member
Posts: 202
Joined: Wed Nov 17, 2004 12:00 am
Location: Germany
Contact:

Post 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.
Cmaranec
Member
Member
Posts: 45
Joined: Sat Oct 21, 2006 1:07 pm
Location: Czech Republic

heh...

Post by Cmaranec »

Can you (or anybody other) send me an example of your simple OS with .BAT file??? It will be better.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Post 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?
Cmaranec
Member
Member
Posts: 45
Joined: Sat Oct 21, 2006 1:07 pm
Location: Czech Republic

yes

Post by Cmaranec »

Yes, i know. How i insert this classes to my kernel?
User avatar
bluecode
Member
Member
Posts: 202
Joined: Wed Nov 17, 2004 12:00 am
Location: Germany
Contact:

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