This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: c++ compilation error (undefined reference)
- From: Andrea Bocci <fwyzard at inwind dot it>
- To: Baraclese <webmaster at baraclese dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 28 Oct 2002 12:12:42 +0100
- Subject: Re: c++ compilation error (undefined reference)
The compiler is telling you that it cannot find the TGA constructor. Well,
can't blame it, you didn't provide one :-)
IIRC, to get the default constructor (doing nothing but allocating the
class itself, more or less) and esructor (idem), you sould not declare them.
If you do, the compiler expect you do define them, too, hence the link error.
fwyzard
At 01.48 28/10/2002 +0100, Baraclese wrote:
Hi, I wrote a TGA header file and I wanted to test it with a small main file.
tga.h looks something like this:
class TGA
{
public:
TGA();
TGA(char *filename);
~TGA();
bool load(char const *filename);
}
tga.cpp looks like this:
#include "tga.h"
using namespace std;
main()
{
TGA image;
cout << "Filename: ";
cin >> image.filename;
if (image.load(image.filename))
cout << "File successfully read./n";
return 0;
}
When compiling using gcc 3.2 I receive the following error message:
$ g++ -mno-cygwin -lstdc++ f:/projects/cpp/tga.cpp -o tga.exe
/cygdrive/c/WIN98/TEMP/cccSDKcK.o(.text+0x9f0):tga.cpp: undefined
reference to `TGA::TGA()'
What's the problem here?
regards,
Baraclese