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 > learning c++

learning c++
Thread Tools
Fresh-Faced Recruit
Join Date: Nov 2001
Status: Offline
Reply With Quote
Jan 10, 2002, 12:58 AM
 
i don't know anything about C++ so can anyone tell me why am I getting....

/usr/bin/ld: Undefined symbols:
___ls__7ostreamPCc
_cout

...when I try to compile...

#include <iostream.h>
void main()
{
cout << "Hello World.";
}
     
Forum Regular
Join Date: Nov 2000
Location: The voice inside your head
Status: Offline
Reply With Quote
Jan 10, 2002, 03:53 AM
 
I'm having exactly the same problem, cc doesn't seem to like cout and cin for some reason.
     
Forum Regular
Join Date: Nov 2000
Location: The voice inside your head
Status: Offline
Reply With Quote
Jan 10, 2002, 04:01 AM
 
Gah, a search of the forum archives shows that you need to use the command c++ instead of cc when compiling c++ programs in the command line.
     
Dedicated MacNNer
Join Date: Apr 2001
Location: Bethesda, MD
Status: Offline
Reply With Quote
Jan 10, 2002, 08:29 AM
 
Originally posted by lythari:
<STRONG>Gah, a search of the forum archives shows that you need to use the command c++ instead of cc when compiling c++ programs in the command line.</STRONG>
Yup, when you use "cc" the compiler assumes is a C program and so it links with the C libraries. cin and cout are C++ constructs, so you need to compile with "c++". They're the essentially the same program, but they invoke the linker, "ld" different.

dave
     
Fresh-Faced Recruit
Join Date: Nov 2001
Status: Offline
Reply With Quote
Jan 10, 2002, 10:30 AM
 
ah yes, that seems to be it... thank you and thank you.
     
Dedicated MacNNer
Join Date: Nov 2000
Status: Offline
Reply With Quote
Jan 14, 2002, 12:20 AM
 
This is for those who might be interested in what is going on.

c++ passes the '-lstdc++' flag on to the linker. 'c++ -o foo foo.c' and 'cc -o foo foo.c -lstdc++' work equally well.
     
Dedicated MacNNer
Join Date: Nov 2000
Status: Offline
Reply With Quote
Jan 14, 2002, 12:23 AM
 
Double post. Move along, nothing to see here.

[ 01-14-2002: Message edited by: int69h ]
     
   
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 09:42 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