ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

undifined reference to ... catkin_make error despite CMakeLists has the files

asked 2021-01-18 10:40:14 -0600

robotSquirrel gravatar image

updated 2021-01-19 17:00:04 -0600

sloretz gravatar image

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})
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2021-01-20 03:38:25 -0600

robotSquirrel gravatar image

I solved it...

Something must have gone wrong during compilation so that I had corrupt files in my catkin build and devel folders. I deleted the folders for my project (obstacle_avoidance) in both bild and devel and started catkin_make again. It compiled without problems.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2021-01-18 10:40:14 -0600

Seen: 76 times

Last updated: Jan 20 '21