Hi everyone, I have been reading through this forum for a while now, and I love the FAQ site its mad but the only thing i don't understand is GCC and i386 Machines.
My first problem is that when I complie a simple C Program e.g. a hello world program, gcc -c /home/usr/hello.c it comes up with an error, saying that 'cout` error or some thing, I am using the code from cprogramming.com (The Tutorials, Leasson 1. The First Example) can some one help me, is it because it is C++ and not C.
And a i386 machine, is that really needed for devaloping a OS, why or why not. Thank you for your help.
GCC Help and i386 Machine Help
Re:GCC Help and i386 Machine Help
I'm no C guru, but something along the lines of:Jankins wrote: My first problem is that when I complie a simple C Program e.g. a hello world program, gcc -c /home/usr/hello.c it comes up with an error, saying that 'cout` error or some thing, I am using the code from cprogramming.com (The Tutorials, Leasson 1. The First Example) can some one help me, is it because it is C++ and not C.
Code: Select all
#include <stdio.h>
int
main()
{
printf("HELLO WORLD!\n");
return 0;
}
Nope, you don't need an x86 machine. The reason that most people use x86 is because:And a i386 machine, is that really needed for devaloping a OS, why or why not. Thank you for your help.
- There is a lot of x86 documentation on the web
- There are plenty of people knowledgable about x86 that can help you out
- x86 hardware is cheap and getting hold of a test machine won't break the bank
Of course someone has to go first....
Re:GCC Help and i386 Machine Help
These tutorials are C++, not C. Rename your source files to .cpp and they should work.Jankins wrote: My first problem is that when I complie a simple C Program e.g. a hello world program, gcc -c /home/usr/hello.c it comes up with an error, saying that 'cout` error or some thing, I am using the code from cprogramming.com (The Tutorials, Leasson 1. The First Example) can some one help me, is it because it is C++ and not C.
Re:GCC Help and i386 Machine Help
Another Question, After I complie it, How to i exec it? or is there more to just Complieing the file?
Re:GCC Help and i386 Machine Help
Judging by the path you gave it looks like you're on *nux so a simple ./a.out should do the trick as long as it's executable. chmod u+X a.out first if it isn't. I'm assuming a.out is the output file here, that's what GCC gives as default, it may be a different filename on your comp.
***
Off-topic:
Shouldn't this be in the general programming forum?
***
Off-topic:
Shouldn't this be in the general programming forum?
Re:GCC Help and i386 Machine Help
As Curufir said, the default executable file is usually [tt]a.out[/tt] ; you should be able to rename the file afterward using [tt]mv[/tt] as usual:
[tt]mv a.out hello[/tt]
If you want to specify the name of the output file at compile time, you should use the [tt]-o[/tt] option, like so:
[tt]gcc -o hello hello.cpp[/tt]
I'd also suggest using the 'all warnings' option ([tt]-Wall[/tt]) to get the most error checking. While the warning messages can get annoying, there usually are good reasons for them, and it's a good practice to keep debugging code until it compiled cleanly (i.e., with no warnings, not just no errors). At the very least, you should learn to know what the warnings mean, and when you can disregard them (not often).
While you don't really need it yet, you'll want to learn how to use [tt]make[/tt]. It will not only automate the compile (so you don't need to enter the whole compiler invocation each time you recompile), it will also keep track of the dependencies between files, and can determine which files have been updated and only compile those which have, and clean up the temporary files afterwards. Very important later on when you might have a dozen or more files to compile and link for a big program. However, writing makefiles is something of an art unto itself...
HTH. C&CW.
[tt]mv a.out hello[/tt]
If you want to specify the name of the output file at compile time, you should use the [tt]-o[/tt] option, like so:
[tt]gcc -o hello hello.cpp[/tt]
I'd also suggest using the 'all warnings' option ([tt]-Wall[/tt]) to get the most error checking. While the warning messages can get annoying, there usually are good reasons for them, and it's a good practice to keep debugging code until it compiled cleanly (i.e., with no warnings, not just no errors). At the very least, you should learn to know what the warnings mean, and when you can disregard them (not often).
While you don't really need it yet, you'll want to learn how to use [tt]make[/tt]. It will not only automate the compile (so you don't need to enter the whole compiler invocation each time you recompile), it will also keep track of the dependencies between files, and can determine which files have been updated and only compile those which have, and clean up the temporary files afterwards. Very important later on when you might have a dozen or more files to compile and link for a big program. However, writing makefiles is something of an art unto itself...
HTH. C&CW.