Re: gcc/g++ fails to compile

Glynn Clements <[email protected]>
Newsgroups org.kernel.vger.linux-c-programming
Message-ID <[email protected]>
Phil C wrote:

> > It is hard to tell what the problem is without sample code and the
> > exact error message along with some details about your system
> > configuration.
> 
> 
> >Regards
> 
>  >       \Steve
> 
> Sorry for the lack of information I hope this makes the situation more
> clear. I'm using Ubuntu Linux 8.04 and every current stable patch
> kernel wise. GCC is version 4.3 Remaining info is as follows.
> 
> //Sample Code
> 
> #include<iostream>
> using namespace std;
> 
> int main() {
>     cout <<"Hello World";
>     return 0;
> }
> 
> //Error message copied from terminal
> 
> /tmp/ccERz0tv.o:
> In function `std::__verify_grouping(char const*, unsigned int,
> std::basic_string<char, std::char_traits<char>,
> std::allocator<char> > const&)':
> test.cpp:(.text+0xe):
> undefined reference to `std::basic_string<char,
> std::char_traits<char>, std::allocator<char> >::size()
> const'

[more "undefined reference" errors snipped]

For linking, you need to either use "g++" (rather than "gcc"), or
explicitly link against the C++ library with "-lstdc++". IOW:

	g++ test.cc
or:
	gcc test.cc -lstdc++

-- 
Glynn Clements <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.