Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > help with cc compiler

help with cc compiler
Thread Tools
Fresh-Faced Recruit
Join Date: Jul 2001
Location: San Diego, CA
Status: Offline
Reply With Quote
Dec 18, 2001, 03:37 AM
 
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
Reply With Quote
Dec 18, 2001, 09:20 AM
 
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
Reply With Quote
Dec 18, 2001, 09:48 AM
 
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
Reply With Quote
Dec 18, 2001, 02:31 PM
 
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
Reply With Quote
Dec 18, 2001, 04:14 PM
 
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
Reply With Quote
Dec 19, 2001, 12:44 AM
 
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 ]
     
reyzell  (op)
Fresh-Faced Recruit
Join Date: Jul 2001
Location: San Diego, CA
Status: Offline
Reply With Quote
Dec 19, 2001, 01:00 AM
 
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
Reply With Quote
Dec 20, 2001, 02:18 PM
 
Using the c++ command does the same thing as specifying cc with the necessary flags.

Wade
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:07 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2