Question: I likely have a ROS Cpp library problem. My cpp is not linking to some of my hpp content. When it's just cpp, it works, when i add ros, it doesn't anymore. I'm not cpp fluent myself, what should i do to solve that?
Error:
/usr/bin/ld: CMakeFiles/node.dir/src/main.cpp.o: in function `main':
main.cpp:(.text+0x244): undefined reference to `A::A(int, char**)'
/usr/bin/ld: main.cpp:(.text+0x258): undefined reference to `A::~A()'
collect2: error: ld returned 1 exit status
Package config: I'm using Ros noetic
-->Ros_package
- include
- A.hpp
- all the h & hpp stuff
- src
- main.cpp
- all the c & cpp stuff
A.hpp content
#ifndef A_HPP
#define A_HPP
/*** I N C L U D E S **********************************************************/
#include QT/ another .hpp, another .h
/* D E F I N E S ************************************************************/
/* Debug helper */
/* S T R U C T U R E **********************************************************/
typedef struct stuff
/*** C L A S S ****************************************************************/
class A : public QThread
{
Q_OBJECT
public:
A (int argc, char** argv);
virtual ~A (void);
void run (void);
private:
method
public slots:
method
private:
stuff
};
#endif // A_HPP
Main.cpp content:
/* I N C L U D E S ************************************************************/
#include <QApplication>
#include <ros/ros.h>
#include <A.hpp>
/* M A I N ********************************************************************/
int main (int argc, char** argv)
{
QApplication app(argc, argv);
/* Launch main thread */
ros::init(argc, argv, "test_dammit");
A mainThread (argc, argv);
/*stuff
return 0;
}
Cmakefile content:
cmake_minimum_required(VERSION 3.0.2)
project(ros_package)
catkin_package()
find_package(catkin REQUIRED roscpp)
## System dependencies are found with CMake's conventions
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Network REQUIRED)
include_directories(
include
${catkin_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/include
)
add_executable(node src/main.cpp )
## Specify libraries to link a library or executable target against
target_link_libraries(node
${catkin_LIBRARIES} Qt5::Widgets Qt5::Network
)
Context: I'm adapting a non Ros cpp package to Ros. SO i know the hpp and cpp are correctly written. I Think I'm getting hpp/cpp library link troubles.
I can't seem to find a solution that works online. I tried many CmakeFile adaptation as well, no luck.
What should i look for?
Thank you all!
EDit:
This Link is pertinent if the code cpp doesn't work at all BUT the code WITHOUT ROS works perfectly. So the problem arises while doing Ros integration.