On Sat, Jan 01, 2005 at 08:43:51AM -0500, Jonathan Levi MD wrote:
> Happy New Year, all!
> 
> I've initiated a return to studying C++, but am having trouble 
> linking a simple program (following log edited for ease of reading):
> 
> jonathan$ cat hello.cpp
> 
> #include<iostream>
> int main(){
>         std::cout << "Hello World!\n";
>         return 0;
> }
> 
> jonathan$ gcc -o hello hello.cpp
> 
> ld: Undefined symbols:
> std::ios_base::Init::Init()
> std::ios_base::Init::~Init()
> std::cout
> std::basic_ostream<char, std::char_traits<char> >& std::operator<< 
> <std::char_traits<char> >(std::basic_ostream<char, 
> std::char_traits<char> >&, char const*)
> ___gxx_personality_v0
> 
> Can someone tell me what's missing? --TIA as always, Jonathan

You're missing the C++ standard library.

Short answer: use g++ instead of gcc.

Longer explanation: gcc and g++ are front-ends to the same compiler;
this compiler determines which language to use based off the file's
extension (which can be overridden by a command-line switch).

However, g++ also automatically links its executables against the C++
standard library, while gcc doesn't.  It is possible to use gcc to link
C++ program by specifying the C++ standard library directly on the
command line.  However, the actual library binary is typically hidden
way down in the gcc installation and can be very hard to find.  Using
g++ is sufficient for almost all cases.

Richard


-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Fink-users mailing list
Fink-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fink-users

Reply via email to