cc / iostream.h / cout problem

brad_umbaugh

Registered
Hi everyone,

I just installed the Apple Developer Tools and the update to it, and I'm trying to compile a simple Hello World type program in OS X from the command line. Unfortunately, I'm being stopped dead in my tracks...

Here's the program:

#include <iostream.h>

void main()
{
cout << "Hello World" << endl;
}

And here's the outpout:

[localhost:~/Dev/test] umbaugh% cc -o brad brad.cc
/usr/bin/ld: Undefined symbols:
ostream:: operator<<(char const *)
ostream:: operator<<(ostream &(*)(ostream &))
_cout
endl(ostream &)

Note that this program works just fine when I'm using project builder, just not from the terminal command line! I'm confused what could be going on here... it looks like it's saying that the operator isn't defined, but I looked at the iostream.h file and the is definitely defined. I'm wondering if it's finding an invalid iostream.h file or something? What folder is iostream.h supposed to be in?

Does anybody have any ideas why this won't work? :) I don't think it bodes well for my overall programming prowess if i can't get a cout statement to work!

Thanks much,
Brad
 
It is also important to note that, obviously, i included "iostream.h" and also tried a simple "iostream" inside the angle brackets after #include.

-Brad
 
Synopsis:

The stream library, including cout and cin are C++ constructs.


Conclusion:

Try "c++" instead of "cc" on the command line.

/Björn
 
Also, try:

cc brad.c -o brad

the "cc" is the GNU C Compiler and compiles the c program you specify at the current directory. The "-o" outputs the name of the program you want, and the "brad" is the program that comes out.

-whitesaint
 
Hmm, this is what I would try:

cc -x c++ -o brad brad.cc

*OR*

rename your C++ file to .cpp and see if cc will catch it as C++ then.

Or you can try both.

You might need to generate a Makefile, since C++ uses a static library for the fun cin/cout stuff.
 
Back
Top