undifined reference to ... catkin_make error despite CMakeLists has the files
Hi all,
I am working on a project with multiple classes with ros neotic and catkin. Without changing my CMakeLists file at all, I suddenly got the "undefined reference to ..." error for all functions of the classes in my external files. I have no Idea why this error suddenly appeard, especally because I didn't change anything in my structure or the external files, just in the main.
I'm still a beginner with both ros and cpp, so any help would be appreciated. I added the files below.
To test this I added "compileTest.cpp" to obstacle_avoidance/src/...:
#include "obstacle_avoidance/oA_output.h"
int main(){
OA_output out;
}
This is the Error I got:
/usr/bin/ld: CMakeFiles/compileTest.dir/src/compileTest.cpp.o: in function `main':
compileTest.cpp:(.text+0x48): undefined reference to `OA_output::OA_output()'
/usr/bin/ld: compileTest.cpp:(.text+0x57): undefined reference to `OA_output::~OA_output()'
My other Files:
obstacle_avoidance/src/oA_output.cpp:
#include "obstacle_avoidance/oA_output.h"
OA_output::OA_output(){
anglePub = outputNode.advertise<std_msgs::Float32>("steeringAngle",10);
velocityPub = outputNode.advertise<std_msgs::Float32>("velocity",10);
};
OA_output::~OA_output(){};
...
obstacle_avoidance/include/obstacle_avoidance/oA_output.h:
#pragma once
# include "ros/ros.h"
# include "std_msgs/Float32.h"
class OA_output{
public:
OA_output();
~OA_output();
...
CMakeLists.txt
cmake_minimum_required(VERSION 3.0.2)
project(obstacle_avoidance)
find_package(catkin REQUIRED COMPONENTS
grid_map_core
grid_map_ros
grid_map_msgs
grid_map_rviz_plugin
grid_map_visualization
roscpp
rviz
std_msgs
)
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES obstacle_avoidance
# CATKIN_DEPENDS grid_map roscpp rviz std_msgs
# DEPENDS system_lib
)
include_directories(
include
${catkin_INCLUDE_DIRS}
)
## Declare a C++ library
add_library(${PROJECT_NAME}
#src/spielwiese.cpp
src/grid.cpp
src/visualiser.cpp
src/polar.cpp
src/dirFinder.cpp
src/oA_output.cpp
src/oA_input.cpp
)
add_executable(spielwiese src/spielwiese.cpp)
target_link_libraries(spielwiese obstacle_avoidance ${catkin_LIBRARIES})
add_executable(mapPublisher src/mapPublisher.cpp)
target_link_libraries(mapPublisher obstacle_avoidance ${catkin_LIBRARIES})
add_executable(compileTest src/compileTest.cpp)
target_link_libraries(compileTest obstacle_avoidance ${catkin_LIBRARIES})