c++ : one file class-in-node to three files class, node, and header
[Note: Prior to this question, my code and package compiled and functioned properly, the issue came from rearranging my file structure etc.]
I am trying to make a single node reusable by separating it into multiple files. This is probably more of a c++ question, but I'm not sure if i need to do something different in my code, or in my CMakeLists...
My original file had this structure:
#include <head_loc/manythings.h>
class ClassName
{
private:
Multiple ClassVariables;
public:
ClassName() // Constructor for publishers etc..
{ }
output function1() // do 1st thing
{ }
output functionN() // do Nth thing
{ }
};
int main(int argc, char** argv)
{
ros::init(argc, argv, "ClassName_Node");
ClassName CN;
ros::spin();
return 0;
}
My three new files have this structure: Node file:
#include <classheader.h>
int main(int argc, char** argv)
{
ros::init(argc, argv, "ClassName_Node");
ClassName CN;
ros::spin();
return 0;
}
Header file :
#ifndef _CLASSHEADER_H
#define _CLASSHEADER_H
#include <head_loc/manythings.h>
class ClassName
{
private:
Multiple ClassVariables;
public:
ClassName(); // Constructor for publishers etc..
output function1(); // do 1st thing
output functionN(); // do Nth thing
};
#endif
Class fucntions :
#include <classheader.h>
ClassName::ClassName() // Constructor for publishers etc..
{ }
output ClassName::function1() // do 1st thing
{ }
output ClassName::functionN() // do Nth thing
{ }
I assumed this format to allow two different ROS nodes to call and use the same class. I get a compile error (truncated to what i believe is the relevant error codes) :
[100%] Building CXX object CMakeFiles/handrail_end_class.dir/src/handrail_end_class.cpp.o
Linking CXX executable /home/benjamin/r2_hydro/devel_isolated/lib/nasa_r2_vision_handrail/handrail_end_class
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 10
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 10
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 12
/usr/bin/ld: /usr ...