I am scratching my head at an error that I am having, I should be passing something simple. The situation is:
I have a h and a cpp file with a class implementation. This has been working well. I copy pasted these files to another project and I am trying to use them
But suddenly I got the
Scanning dependencies of target path_planning
[ 50%] Building CXX object CMakeFiles/path_planning.dir/src/main.cpp.o
[100%] Linking CXX executable path_planning
CMakeFiles/path_planning.dir/src/main.cpp.o: In function `main':
main.cpp:(.text+0x4df6): undefined reference to `PID::PID()'
main.cpp:(.text+0x53b4): undefined reference to `PID::~PID()'
main.cpp:(.text+0x5506): undefined reference to `PID::~PID()'
collect2: error: ld returned 1 exit status
CMakeFiles/path_planning.dir/build.make:94: recipe for target 'path_planning' failed
make[2]: *** [path_planning] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/path_planning.dir/all' failed
make[1]: *** [CMakeFiles/path_planning.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
I haven't changed anything from the project where it worked.
To reproduce the problem here is the code
#ifndef PID_H
#define PID_H
class PID {
public:
PID();
virtual ~PID();
};
#endif // PID_H
and
#include "PID.h"
PID::PID() {}
PID::~PID() {}
in the main file I do
#include "PID.h"
and inside main()
PID pid;
I have tried it by itself (in a minimum example) and it works. So I cannot understand why it gives this error with my main file.