PDA

View Full Version : Problems using .h-files



Magnus W
12-09-2000, 12:55 PM
I have been working on a small OpenGL project lately and just started using Codewarrior. I have had some problems getting Codewarrior to link the program properly when using .h/.cpp files in combination.
Everything works if I put a
#include "file.cpp" at the end of my "file.h" header file, (or if I put all of the code in a .cpp file and include that one in the main program) but otherwise it doesn't seem to find the .cpp file at all.
Everything compiles nicely, but the linker gives me the following error:

Link Error : undefined 'M_Filter3f::~M_Filter3f()' (descriptor)
Referenced from '__sinit_TerraTester3_cpp' in TerraTester3.cpp

Does anybody know what could be wrong?

Magnus W
12-09-2000, 01:31 PM
Update:
It seems there's a problem with functions and constructors using "inline".
If I remove the inline then everything works fine. The question is - why does it work when everything is included in one single file and not when in .h/.cpp-files ?

conradwt
12-10-2000, 12:57 AM
Hi, I was wondering, do you have a small example program that produces this error message? Anyway, if you have a class called M_Filter3f

Then all you have to do is define it in the .h or .cpp file as follows:

in .h:

#ifndef __M_Filter3f__
#define __M_Filter3f__

class M_Filter3f
{
public:
~M_Filter3f() {}
}

#endif // __M_Filter3f__

in .c:

M_Filter3f::~M_Filter3f() {}

Doing one of the following should resolve
the link error message. I'll create a simple class and see what gives and I'll
talk to you later.

-Conrad


Originally posted by Magnus W:
I have been working on a small OpenGL project lately and just started using Codewarrior. I have had some problems getting Codewarrior to link the program properly when using .h/.cpp files in combination.
Everything works if I put a
#include "file.cpp" at the end of my "file.h" header file, (or if I put all of the code in a .cpp file and include that one in the main program) but otherwise it doesn't seem to find the .cpp file at all.
Everything compiles nicely, but the linker gives me the following error:

Link Error : undefined 'M_Filter3f::~M_Filter3f()' (descriptor)
Referenced from '__sinit_TerraTester3_cpp' in TerraTester3.cpp

Does anybody know what could be wrong?

conradwt
12-10-2000, 12:59 AM
Hi, I forgot to tell you that the program was receiving a link error because it couldn't locate the destructor for the class. Just define it and you should be good to go.

-Conrad


Originally posted by conradwt:
Hi, I was wondering, do you have a small example program that produces this error message? Anyway, if you have a class called M_Filter3f

Then all you have to do is define it in the .h or .cpp file as follows:

in .h:

#ifndef __M_Filter3f__
#define __M_Filter3f__

class M_Filter3f
{
public:
~M_Filter3f() {}
}

#endif // __M_Filter3f__

in .c:

M_Filter3f::~M_Filter3f() {}

Doing one of the following should resolve
the link error message. I'll create a simple class and see what gives and I'll
talk to you later.

-Conrad

Magnus W
12-11-2000, 01:55 PM
Conrad> Thanks for your help. A friend of mine found the problem though - I had put the code for the constructor and destructor, declared "inline", in the .cpp-file. The compiler doesn't like that a lot :-)