Page 1 of 2
TCC problem
Posted: Thu Aug 30, 2007 6:04 pm
by Buck1000
Ok, im trying to compile a simple Hello World C program in TCC (Tiny C Compiler), and at the top of the program there is a include statement for iostream, because the program uses cout. And TCC can't find iostream. I'v moved iostream into several places, including c:\, c:\tcc, c:\tcc\tcc, and nothing worked. Where do the libs go?
Posted: Thu Aug 30, 2007 8:16 pm
by Alboin
cout\iostream is C++. TCC only is a C compiler. Try:
Code: Select all
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("Hello World!\n");
return 0;
}
Or install CYGWIN\MINGW and g++. (The GNU C++ compiler.)
Posted: Fri Aug 31, 2007 5:01 am
by JamesM
I suggest you use GCC (the GNU compiler collection) with cygwin (linux environment for windows).
GCC is much more featured than TCC, and comes with LD, which will enable you to link your kernel. The fact that you are having difficulty with a hello world app in C suggests to me that you do not have the required prerequisite knowledge to code an OS at this time. Do not take this as a personal affront - There is only (possibly) one task that is more difficult to achieve than writing an OS, that being writing a compiler. It is NOT a simple task, not something you can code up in minutes to show off to your friends. You NEED previous experience and knowledge in low-level development. (at least in C. Even if you want to code in basic, you'll have to know how things work under the hood, and C is as low level as you can get before ASM).
JamesM
Posted: Fri Aug 31, 2007 2:08 pm
by jerryleecooper
Ive heard somewhere that the second hardest thing to program, after an OS ( I think, not just a microkernel, of course) was a compiler. Writing a compiler is more theory than practice, and writing an OS is more practice than theory, some persons are better at one thing than others.
A lot of people makes a small kernel, sometimes with a GUI, and lot of people makes interpreters for some languages, sometimes with bytecodes, and sometimes resulting in to machine language.
Making a compiler is something I will try one day.
Posted: Fri Aug 31, 2007 3:16 pm
by eboyd
In your reply in the other topic you said you used dev-cpp. dev-cpp is a great IDE (Integrated Development Enviornment) to use to learn CPP. Dev-CPP uses the MinGW compiler as others have mentioned. It supports, C and CPP which will be very useful in learning. "cout" is in "iostream" but don't forget:
Code: Select all
#include <iostream>
int main(){
std::cout << "Hello World!" << std::endl;
system("pause") // This is a Windows-only line.
return 0;
}
is the same as:
Code: Select all
#include <iostream>
using namespace std; // If we add this here...
int main(){
cout << "Hello World!" << endl; // We don't need to prepend with "std" here
system("pause");
return 0;
}
I've never used TCC but it sounds like it's a bit too minimalistic for practical learning purposes.
A great & fun book to learn CPP/C is "C++ Without Fear" by Brian Overland (i think that's his name?) It might not be the most complete or the most politically correct (in terms of coding conventions) but its definately good for getting your feet wet.
As far as OS...
...you probably know about as much as I do. I'm new to that whole spiel as well, but like I said the tutorials are the best way to get started, if for no other reason than to at least learn all the different parts that are involved in the underworkings of an OS. I sure learned a lot, though I feel i'm still a ways off from being able to hammer out the code for my own operating system...
Posted: Fri Aug 31, 2007 4:18 pm
by Buck1000
Yeah, I just learned about the
thing a few days ago, because I've been using an old Borland 4.5 C++ IDE up untill a few weeks ago, and I've never had the need for that line...
Whats the 'endl' for?
A great & fun book to learn CPP/C is "C++ Without Fear" by Brian Overland (i think that's his name?)
Well, I couldn't find that book at my library, but I did find "C++ in plain English" by the same guy. I've been reading "C++ Primer Plus" by Stephen Prata, but its kinda old - 1998. So it might be wrong in some places if anythings changed...
As far as OS...
...you probably know about as much as I do. I'm new to that whole spiel as well, but like I said the tutorials are the best way to get started
Yeah, I've managed to find a few tutorials on making an OS, but they are in Assembly, so I still don't know how to use C++ for OS dev. But I did learn more about computers.
The thing that comfuses me the most, is how I get C++ into a binary file. Heres the program I tried to make into a .bin file -
Code: Select all
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello World!!";
cin.get();
return 0;
}
I saved it as a .cpp file, and then went into DOS and did this -
(Of course I do have gcc and ld)
Code: Select all
gcc -c helloW.cpp
ld helloW.o -oformatbinary LOADER.BIN
Or something like that. The reason that I used LOADER.BIN instead of helloW.bin is that I got a bootloader that loads a file called LOADER.BIN off a floppy with the bootloader loaded in the first sector. I used DEBUG to load it, and copied the LOADER.BIN onto the floppy, and nothing happened when I used it... So I would just LOVE to know how to get a .cpp file into a .bin file. And if you were wondering, here is the bootloader -
http://www.mediafire.com/?c3g21zmf9xg
Posted: Fri Aug 31, 2007 7:34 pm
by eboyd
"endl" (end-line) is similar to "\n" thye do essentially the same thing, but "\n" is the actual carriage-return character.
well, one major problem with this is you can't "include" (by using the #include statement) any "system-includes".
Basically when you say "#include <iostream>", you're performing a search of the "system" (be it Windows, Linux, etc.) for the "iostream" header files, problem is, there's no system to search! (i.e. your OS that you're building doesn't have them yet).
When using C or CPP for the first stages of OS development, the only thing available to you are "user-defined includes" (header files, cpp files, etc. that you've written yourself) granted they, and all your code only contains "core language" (everything in C or CPP that doesn't require a "system-include" like iostream).
SO, this is not valid:
Code: Select all
#include <iostream>
using namespace std;
int main(){
cout << "This will not work in OS development!" << endl;
cin.get();
return 0;
}
But if "MyHeader.h" is something you've written, the following is OK:
Code: Select all
#include "MyHeader.h"
int main(){
return 0;
}
This might not seem terribly useful to you, but iostream isn't terribly useful for building an OS! iostream is useful for testing a program by giving you basic i/o capabilities through a command window. using the iostream will be beneficial to you for learning CPP too.
The REAL functionality of CPP that makes it so useful is OOP (object-oriented programming). I don't know what your programming experience is, but OOP is a whole subject in and of itself. A more procedural language like assembly or C is typically better suited for OS development, at least the beginning stuff.
I would suggest learning CPP, I personally think its easier to learn C if you know CPP than the other way around. After all, CPP is really just an extension of the C language.
Posted: Fri Aug 31, 2007 11:26 pm
by Buck1000
The REAL functionality of CPP that makes it so useful is OOP (object-oriented programming). I don't know what your programming experience is, but OOP is a whole subject in and of itself.
Well, I know what structures are, along with functions too, and I'm getting close to classes...
Well, without iostream, the only other way I can think of is to use ASM. So how do you use ASM in C++? (Oh, and I read somewhere that when the pc boots and your OS takes over, only BOIS interrupts are available... Does this mean that I can't write my own ASM code that does the same thing as the other interupts? And example would be how you can use the DOS interrupt 10h, or so I think thats what it is, to print something to the screen. Can't I write directly to the 'video memory' or whatever its called to get something on the screen? If I could, then I could maybe make a function in C++ that does that for me in ASM, IF I knew how to do it...)
[/code]
Posted: Fri Aug 31, 2007 11:50 pm
by Alboin
cout is simply a class with the << operator overloaded. You can create your own cout for your OS by directly accessing video memory, as you said. To access said memory, one must write to 0xb8000. Check out the wiki. There should be some examples there on how to write to it. (You can do it in C++. Pointers are your friends.)
Also, you can only use BIOS interrupts in 16bit. While in 32 bit protected mode, you can't use them.
Posted: Fri Aug 31, 2007 11:57 pm
by Buck1000
But in 32 bit protected mode, can you use any?
You can do it in C++. Pointers are your friends.
So you just make a pointer and get it to point to 0xb80000, and then you use it to write a value there, right? I think I'm finally starting to understand things!
Posted: Sat Sep 01, 2007 12:00 am
by Alboin
Buck1000 wrote:But in 32 bit protected mode, can you use any?
Nope. You have to write your own drivers.
Buck1000 wrote:You can do it in C++. Pointers are your friends.
So you just make a pointer and get it to point to 0xb80000, and then you use it to write a value there, right? I think I'm finally starting to understand things!
Yup. However, you have to write two bytes for each character displayed. First you write the actual character, at say, 0xb8000. Then you write the attribute, which is the background\foreground color at 0xb8001. (7 is the usual attribute. White characters on black.)
This is easy, as you can just access a pointer as an array:
Code: Select all
video_pointer[0] = 'a';
video_pointer[1] = 7;
Posted: Sat Sep 01, 2007 12:09 am
by Buck1000
Ok cool, I'm gonna go try this out!
EDIT - But... Um... How do you change a pointer to point to something you want it too? All I know is this -
Posted: Sat Sep 01, 2007 8:44 am
by Alboin
Code: Select all
unsigned char *video_pointer = (unsigned char*)0xb8000;
Posted: Sat Sep 01, 2007 11:15 am
by eboyd
You can mix "C" and assembly, and therefore you can use it in "CPP" as well, but you'll have to do an extern "C" for it to work.
Code:
unsigned char *video_pointer = (unsigned char*)0xb8000;
Basically if you do this:
gives you not an address, but what is pointed to.
So it's the opposite of:
assuming "y" is a pointer.
Posted: Sat Sep 01, 2007 11:06 pm
by Buck1000
Does it have to be an unsigned char?