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: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
++ 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: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