C compiler not working

Ashira

Registered
Forgove me if this has been posted before (I haven't seen it) but I installed the dev tools and the C compiler doesn't work. I'm trying to learn C as a prelude to Obj-C. When trying to cc test.c I get a few hundred lines of errors with the include files:

/usr/include/gcc/darwin/2.95.2/g++/streambuf.h:378: syntax error, found `::'
/usr/include/gcc/darwin/2.95.2/g++/iostream.h:50: syntax error, found `*'
/usr/include/gcc/darwin/2.95.2/g++/streambuf.h:379: undefined type, found `virtual'

and so on. I have a very simple Hello World style program I'm trying to compile as a test and I did manage to get it to work with c++ test.c but I assume this'll only work for a short while until the differences in C/C++ start cropping up.

This is after a reformat and reinstall (for other reasons also) of 9.1, X and Dev Tools. Any suggestions?
 
I could be mistaken, but :: and virtual aren't parts of C. Classes and late binding are only supported in the later incarnations (C with Classes, C++). And even then there are issues.

If you mean that you are compiling C++ stuff, well, I wouldn't learn C++ as a prelude to obj.C - I might learn Java... the concepts are there and the syntax is Sooooo much cleaner. and it's C based, so those obscurities and language anomolies will transfer nicely.

But it sounds to me like someone is referring to C++ as simply C and you're attempting to utilize C++ constructs.
 

But it sounds to me like someone is referring to C++ as simply C and you're attempting to utilize C++ constructs.

No, I want to and am trying to learn C. I read somewhere that cc is the command for the C compiler. Perhaps I am mistaken. Assuming I have a text file of source code called program.c, how do I compile it?
 
#include <iostream>

OK, I think I'm closer to understanding, but that means I'm farther from being able to help...

cc is a compiler, but I think it's a C/C++/obj.C compiler. I really don't know how to make it run from the command line. That syntax made me angry enough on other platforms to run away and program in an IDE like CodeWarrior or Project Builder.

sprintf ("%s, Good luck with C");
/* sorry I'm not more useful. */
 
if you only have one source file and you don't want to link to frameworks etc then calling cc form the command line is fairly simple.

cc -o (output app name) (source file name).c

peter

[for those that thought that I had it wrong, i didn't. I used greater than and less than sybols, sorry :( ]
 
Originally posted by Ashira

Assuming I have a text file of source code called program.c, how do I compile it?

You'll have to cc -o <progName> <source>
for example:
cc -o machin machin.c
And then you'll get a "machin" that you can launch by typing ./machin<RETURN>

This way, cc will try to recognize the file type you are compiling with its suffix:
- file.c: C
- file.cpp: C++
- file.m: ObjC

But if you want to force it, specify the language:
cc -x c++ -o machin machin.c

For C++, you'll have to link with the C++ additions library:
cc -x c++ -o machin machin.cp -lstdc++

--
Guillaume Outters
http://www.esiee.fr/~outtersg
 
no, you're not wrong (see my post in your other thread)

it's the gray CD in the OSX box labeled 'Developer Tools', how could you miss it? :)
 
There's a nice visual development environment called Project Builder and there's "cc" and "cpp" for command line compiling.

-Rob
 
Back
Top