Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > N00b looking for GCC error help.

Reply
Thread Tools

N00b looking for GCC error help.

 
 
sublimanized@gmail.com
Guest
Posts: n/a
 
      02-28-2007
Hello all ... here is my problem. I just got the book "Teach Yourself C
++ in 21 Days"

Setup:
Fedora Core 6 - i386
GCC 4.1.1

Again, I am a complete newcomer to C++, and this is one of the first
examples out of the book. I want to know why exactly this doesn't
clean compile, and how would i fix it?


################################################## ###################
#include <iostream>

int Add (int x, int y)
{
std::cout << "In Add(), recieved " << x << " and " << y << "\n";
return (x+y);
}

int main()
{
using std::cout;
using std::cin;

cout << "I'm in main()!\n";
int a, b, c;

cout << "Enter two nunber: ";
cin >> a;
cin >> b;

cout << "\nCalling Add()\n";
c=Add(a,b);
cout << "\nBack in main().\n";
cout << "c was set to " << c;
cout << "\nExiting ... \n\n";

return 0;
}
################################################## #########




$ gcc ./Func.cpp -o Func

/tmp/cc3B71PJ.o: In function
`__static_initialization_and_destruction_0(int, int)':
Func.cpp.text+0x23): undefined reference to
`std::ios_base::Init::Init()'
/tmp/cc3B71PJ.o: In function `__tcf_0':
Func.cpp.text+0x6c): undefined reference to
`std::ios_base::Init::~Init()'
/tmp/cc3B71PJ.o: In function `Add(int, int)':
Func.cpp.text+0x83): undefined reference to `std::cout'
Func.cpp.text+0x8: undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std:perator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
Func.cpp.text+0x99): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >:perator<<(int)'
Func.cpp.text+0xa9): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std:perator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
Func.cpp.text+0xba): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >:perator<<(int)'
Func.cpp.text+0xca): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std:perator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
/tmp/cc3B71PJ.o: In function `main':
Func.cpp.text+0xf2): undefined reference to `std::cout'
Func.cpp.text+0xf7): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std:perator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
Func.cpp.text+0x106): undefined reference to `std::cout'
Func.cpp.text+0x10b): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std:perator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
Func.cpp.text+0x119): undefined reference to `std::cin'
Func.cpp.text+0x11e): undefined reference to
`std::basic_istream<char, std::char_traits<char> >:perator>>(int&)'
Func.cpp.text+0x12c): undefined reference to `std::cin'
Func.cpp.text+0x131): undefined reference to
`std::basic_istream<char, std::char_traits<char> >:perator>>(int&)'
Func.cpp.text+0x140): undefined reference to `std::cout'
Func.cpp.text+0x145): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std:perator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
Func.cpp.text+0x169): undefined reference to `std::cout'
Func.cpp.text+0x16e): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std:perator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
Func.cpp.text+0x17d): undefined reference to `std::cout'
Func.cpp.text+0x182): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std:perator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
Func.cpp.text+0x193): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >:perator<<(int)'
Func.cpp.text+0x1a2): undefined reference to `std::cout'
Func.cpp.text+0x1a7): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std:perator<<
<std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
/tmp/cc3B71PJ.o.eh_frame+0x11): undefined reference to
`__gxx_personality_v0'
collect2: ld returned 1 exit status

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      02-28-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
>
> Again, I am a complete newcomer to C++, and this is one of the first
> examples out of the book. I want to know why exactly this doesn't
> clean compile, and how would i fix it?
>
>
> $ gcc ./Func.cpp -o Func
>

g++ ./Func.cpp -o Func

--
Ian Collins.
 
Reply With Quote
 
 
 
 
Marcelo Pinto
Guest
Posts: n/a
 
      02-28-2007
On 28 fev, 17:02, (E-Mail Removed) wrote:
> Hello all ... here is my problem. I just got the book "Teach Yourself C
> ++ in 21 Days"

[snip]

You should be using "Accelerated C++" or "You Can Do It" to start in C+
+.

>
> Setup:
> Fedora Core 6 - i386
> GCC 4.1.1
>
> Again, I am a complete newcomer to C++, and this is one of the first
> examples out of the book. I want to know why exactly this doesn't
> clean compile, and how would i fix it?
>
>

[snip]
> $ gcc ./Func.cpp -o Func


This is off-topic here, but try:

$ g++ ./Func.cpp -o Func

The problem seems you didn't link the STL code.

HTH,

Marcelo Pinto

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      02-28-2007
(E-Mail Removed) wrote:
> Hello all ... here is my problem. I just got the book "Teach Yourself
> C ++ in 21 Days"
>
> Setup:
> Fedora Core 6 - i386
> GCC 4.1.1
>
> Again, I am a complete newcomer to C++, and this is one of the first
> examples out of the book. I want to know why exactly this doesn't
> clean compile, and how would i fix it?
>
>
> ################################################## ###################

[..]
> ################################################## #########
>
>
>
>
> $ gcc ./Func.cpp -o Func
>
> /tmp/cc3B71PJ.o: In function
> `__static_initialization_and_destruction_0(int, int)':
> Func.cpp.text+0x23): undefined reference to
> `std::ios_base::Init::Init()'

[..]
> collect2: ld returned 1 exit status


Whenever you have linker errors ('ld' is the linker), you need to
make sure you're supplying all the necessary modules to it. How?
That's an implementation-specific question. Try gnu.g++.help NG.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
sublimanized@gmail.com
Guest
Posts: n/a
 
      02-28-2007
Wow .... i feel like an idiot.

"g++" did the trick.

Thanks for the help, everybody.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting 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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Gcc 3.4.X to Gcc 4.1.X upgrading kas C++ 1 04-22-2010 08:56 PM
GCC 3.4.3 and GCC 4.1.2 ashnin C++ 1 07-07-2008 01:10 PM
Template construction in old gcc 3.3.3 does not compile in gcc 3.4.4 eknecronzontas@yahoo.com C++ 5 09-17-2005 12:27 AM
gcc 2.95 and gcc 3.2 gouqizi.lvcha@gmail.com C++ 8 03-16-2005 02:34 AM
C99 structure initialization in gcc-2.95.3 vs gcc-3.3.1 Kevin P. Fleming C Programming 2 11-06-2003 05:15 AM



Advertisments