ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

"undefined reference" on including *.h *.cpp file to node package

asked 2012-09-30 01:10:26 -0500

MiseryInDevice gravatar image

updated 2014-01-28 17:13:47 -0500

ngrennan gravatar image

Hi guys,

I am trying to build my first project in ROS and so far I am amazed. But since yesterday I got stuck on a problem with including a separate *.h and *.cpp file. I copied the files in a subdirectory in /src called ThirdParty/brisk and added the include paths to the CMakeLists.txt as you can see below (to #include files with <> instead ot ""). I also build an eclipse project and the auto-completition shows me the classes from the included files, but when i try to build it I get the error "undefined reference" as you can see below! Somehow the compiler does not get the *.cpp file (aka brisk.cpp), but I got no idea what I did wrong!

Probably just one little link/include/cmd is missing!!!

I have read a lot about this "undefined reference" error and to mention that: the file brisk.h and brisk.cpp work well in a "not-ROS" project. So the common mistake of forgetting BriskFeatureDetector::BriskFeatureDetector(...) isn't the problem here!

I hope you cam help!!



cmake_minimum_required(VERSION 2.4.6)


# Set the build type.  Options are:
#  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage
#  Debug          : w/ debug symbols, w/o optimization
#  Release        : w/o debug symbols, w/ optimization
#  RelWithDebInfo : w/ debug symbols, w/ optimization
#  MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries
set(ROS_BUILD_TYPE RelWithDebInfo)


#set the default path for built executables to the "bin" directory
#set the default path for built libraries to the "lib" directory

#uncomment if you have defined messages

rosbuild_add_executable(ImgProcEngineNode src/ros_src/rosImgProcEngine.cpp)
rosbuild_add_compile_flags(ImgProcEngineNode "-c -fmessage-length=0 
-march=native -msse2 -msse3 -mssse3 -I/home/me/topological_map/topological_map_v1/src/ThirdParty/brisk 


  <description brief="topological_map_v1">
  <review status="unreviewed" notes=""/>

  <depend package="opencv2"/>
  <depend package="sensor_msgs"/>
  <depend package="rospy"/>
  <depend package="roscpp"/>

     <cpp cflags="-msse2 -msse3 -mssse3 -I/ThirdParty/brisk -I/ThirdParty/brisk/agast"/>
     <intel_cpp cflags="-msse2 -msse3 -mssse3"/>


#include "ros/ros.h"
#include "std_msgs/String.h"
#include "topological_map_v1/rosImageIn.h"
#include <boost/shared_ptr.hpp>
#include <opencv/cv.h>
#include <opencv/ml.h>
#include <opencv2/core/core.hpp>
#include <opencv2/core/mat.hpp>
#include <opencv2/core/operations.hpp>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <brisk.h>

#include <iostream>
#include <vector>
#include <sstream>
using namespace std;
using namespace cv;

int main(int argc, char **argv)
  ros::init(argc, argv, "talker");

  ros::NodeHandle n;

  Ptr<FeatureDetector> _detector = new BriskFeatureDetector(90,4);
  Ptr<DescriptorExtractor> _extractor = new BriskDescriptorExtractor(false);


Console Output after "make"

CMakeFiles/ImgProcEngineNode.dir/src/ros_src/rosImgProcEngine.o: In function `main':
/home/me/topological_map/topological_map_v1/src/ros_src/rosImgProcEngine.cpp:31: undefined reference to `cv::BriskFeatureDetector::BriskFeatureDetector(int, int)'
/home ...
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-09-30 16:50:54 -0500

updated 2012-10-03 15:15:48 -0500

mmmmm... you should indicate rosbuild_add_executable where to find the file where the undefined references are implemented (brisk.cpp)

try to change this line

rosbuild_add_executable(ImgProcEngineNode src/ros_src/rosImgProcEngine.cpp)

for this other

rosbuild_add_executable(ImgProcEngineNode src/ros_src/rosImgProcEngine.cpp /home/me/topological_map/topological_map_v1/src/ThirdParty/brisk/brisk.cpp)

Also, I would avoid using absolute paths on CMakeLists.txt, it will be very messy if you want to compile your project on another machine.

Good luck

edit flag offensive delete link more

Question Tools


Asked: 2012-09-30 01:10:26 -0500

Seen: 3,111 times

Last updated: Oct 03 '12