N00b looking for GCC error help.

S

sublimanized

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+0x88): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::eek: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> >::eek:perator<<(int)'
Func.cpp:(.text+0xa9): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::eek: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> >::eek:perator<<(int)'
Func.cpp:(.text+0xca): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::eek: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::eek: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::eek: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> >::eek: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> >::eek: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::eek: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::eek: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::eek: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> >::eek: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::eek: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
 
I

Ian Collins

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
 
M

Marcelo Pinto

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
 
V

Victor Bazarov

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
 
S

sublimanized

Wow .... i feel like an idiot.

"g++" did the trick.

Thanks for the help, everybody.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top