bman
2nd February 2007, 02:05 PM
Hey,
I'm new to c++ although I have a good bit of C programming knowledge. I am trying to compile a very simple program involving classes. Here it is:
// classes example
#include <iostream>
using namespace std;
class CRectangle
{
int x, y;
public:
void set_values (int,int);
int area () {return (x*y);}
};
void CRectangle::set_values (int a, int b)
{
x = a;
y = b;
}
int main ()
{
CRectangle rect;
rect.set_values (3,4);
cout << "area: " << rect.area();
return 0;
}
When I compile with the command show below I get the following errors:
gcc main.cpp -o main.exe
/tmp/ccXJ5ekd.o: In function `__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0x39): undefined reference to `std::ios_base::Init::Init()'
/tmp/ccXJ5ekd.o: In function `__tcf_0':
main.cpp:(.text+0x82): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccXJ5ekd.o: In function `main':
main.cpp:(.text+0xcd): undefined reference to `std::cout'
main.cpp:(.text+0xd2): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
main.cpp:(.text+0xde): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)'
/tmp/ccXJ5ekd.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
Does anyone know what the problem is? My compiler is up to date as far as I can tell. Heres the output of gcc -v:
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.1 20070105 (Red Hat 4.1.1-51)
Hope someone can help. Thanks.
I'm new to c++ although I have a good bit of C programming knowledge. I am trying to compile a very simple program involving classes. Here it is:
// classes example
#include <iostream>
using namespace std;
class CRectangle
{
int x, y;
public:
void set_values (int,int);
int area () {return (x*y);}
};
void CRectangle::set_values (int a, int b)
{
x = a;
y = b;
}
int main ()
{
CRectangle rect;
rect.set_values (3,4);
cout << "area: " << rect.area();
return 0;
}
When I compile with the command show below I get the following errors:
gcc main.cpp -o main.exe
/tmp/ccXJ5ekd.o: In function `__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0x39): undefined reference to `std::ios_base::Init::Init()'
/tmp/ccXJ5ekd.o: In function `__tcf_0':
main.cpp:(.text+0x82): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccXJ5ekd.o: In function `main':
main.cpp:(.text+0xcd): undefined reference to `std::cout'
main.cpp:(.text+0xd2): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
main.cpp:(.text+0xde): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)'
/tmp/ccXJ5ekd.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
Does anyone know what the problem is? My compiler is up to date as far as I can tell. Heres the output of gcc -v:
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.1 20070105 (Red Hat 4.1.1-51)
Hope someone can help. Thanks.