GCC Help and i386 Machine Help

Programming, for all ages and all languages.
Post Reply
Jankins

GCC Help and i386 Machine Help

Post by Jankins »

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.
Curufir

Re:GCC Help and i386 Machine Help

Post by Curufir »

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.
I'm no C guru, but something along the lines of:

Code: Select all

#include <stdio.h>

int
main()
{
   printf("HELLO WORLD!\n");

   return 0;
}
Should do the trick.
And a i386 machine, is that really needed for devaloping a OS, why or why not. Thank you for your help.
Nope, you don't need an x86 machine. The reason that most people use x86 is because:
  • 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
You see the thing is that if you want to code an OS that runs on , for example, SPARC then you're pretty much on your own. Resources start to get fairly limited once you leave the x86 arena (To tell the truth they are even somewhat limited if you leave the C/FASM/NASM/GAS arena) and that scarcity of resources just doubles the effort required to accomplish anything.

Of course someone has to go first.... ;)
Tim

Re:GCC Help and i386 Machine Help

Post by Tim »

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.
These tutorials are C++, not C. Rename your source files to .cpp and they should work.
Jankins

Re:GCC Help and i386 Machine Help

Post by Jankins »

Another Question, After I complie it, How to i exec it? or is there more to just Complieing the file?
Curufir

Re:GCC Help and i386 Machine Help

Post by Curufir »

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?
Schol-R-LEA

Re:GCC Help and i386 Machine Help

Post by Schol-R-LEA »

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