Problems using .h-files

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?

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 ?

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:
[b]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?[/b]

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:
[b]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

[/b]

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

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.