 |
 |
help with cc compiler
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jul 2001
Location: San Diego, CA
Status:
Offline
|
|
I need help compiling the most basic C++ program.
The program shown below is named Hello.cpp:
#include <iostream.h>
int main() {
cout << "Hello.\n";
return 0;
}
running the command: cc Hello.cpp
I get this error message:
/usr/bin/ld: Undefined symbols:
___ls__7ostreamPCc
_cout
But it compiles just fine running the command: c++ Hello.cpp
For some reason I can't get cc to compile this two line program. I have tried "cc -x c++ Hello.cpp" to make it compile as C++, but it already does that because of the cpp extension.
I have this problem because I need to be able to compile C++ programs in ProjectBuilder but it uses the "cc" command and not "c++".
So my question is does anyone know how to compile this program using cc or how to change ProjectBuilder to use c++?
Thanks for any help
reyzell
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Apr 2001
Location: Bethesda, MD
Status:
Offline
|
|
try changing the file name to hello.C. I seemed to recall having problems with extensions. I don't think Project Builder likes .cpp. I certainly have compiled C++ programs with Project Builder, and my files are all .C.
dave
|
|
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
PB compiles correctly under c++ if you name your files right. (.cpp usually. .C, cxx and .cc will probably work).
What error(s) is PB giving you?
|
|
"Against stupidity, the gods themselves contend in vain" (Schiller)
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Apr 2001
Status:
Offline
|
|
It sounds like you're compiling from the command-line. If so, use the c++ command, rather than cc.
Wade
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
I think he realised that, if you read his message properly.
1) What's wrong with using c++ from the command line?
2) Why do you care what PB does? It just needs to *WORK*.
3) Why would you want to change PB to use c++ instead of cc? c++ is just a convenience frontend to cc, anyway.
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Nov 2001
Location: Seattle
Status:
Offline
|
|
The key error message is:
/usr/bin/ld: Undefined symbols:
___ls__7ostreamPCc
_cout
This message is trying to say that there's no code for the cout function. This is true; the implementation for cout isn't in your program, it's in the standard c++ library.
We can add the standard c++ library to your program when we compile it like this:
<font face = "courier">cc Hello.cpp -lstdc++</font>
The -l (ell) option tells the compiler to link with the given library. For example, if you were using a bunch of math functions (sin, cos, sqrt) you might enter
<font face = "courier">cc mathprogram.cpp -lstdc++ -lm</font>
On the command line, I believe -l options need to appear after the source files that use that library.
I'm guessing that c++ links with the standard c++ library by default, (makes sense!) and cc doesn't (not sure why), which explains why your program compiled fine using the c++ compiler and failed with the cc compiler.
Hope this helps.  I only toyed with ProjectBuilder once so I don't remember how to specify the libraries to link with there.. perhaps someone else can pick up where I left off.
[Edit: fixed some grammar; added line breaks for clarity]
[ 12-19-2001: Message edited by: Juggle5 ]
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jul 2001
Location: San Diego, CA
Status:
Offline
|
|
I'm finally home.
There's a lot of good advice here. I will try it right now. First I'll go with Juggle5's suggestion of those extra flags and 2nd I'll try the extensions like .C, .cxx, etc.
I hope it works.
reyzell
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Apr 2001
Status:
Offline
|
|
Using the c++ command does the same thing as specifying cc with the necessary flags.
Wade
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|