0
$\begingroup$

Rosanswers logo

Indigo, Ubuntu 14.04 (Linux Mint 17.1)

I had a problem the other day that turned out to be missing find_package(OpenCV) so that was resolved.
But I have a new one. I have a better tracking test that builds and runs fine outside of ROS. But catkin_make gives this:

catkin_make Base path: /home/bbick/ros_ws Source space: /home/bbick/ros_ws/src Build space: /home/bbick/ros_ws/build Devel space: /home/bbick/ros_ws/devel Install space: /home/bbick/ros_ws/install

Running command: "make cmake_check_build_system" in "/home/bbick/ros_ws/build"

Running command: "make -j6 -l6" in "/home/bbick/ros_ws/build"

[ 0%] Built target dynamic_reconfigure_generate_messages_py [ 0%] [ 0%] Built target roscpp_generate_messages_lisp Built target roscpp_generate_messages_cpp [ 11%] Built target talker [ 22%] Linking CXX executable /home/bbick/ros_ws/devel/lib/inmoovhead/myopencvtest Built target listener [ 22%] Built target roscpp_generate_messages_py [ 22%] [ 22%] [ 22%] Built target std_msgs_generate_messages_lisp Built target std_msgs_generate_messages_py Built target rosgraph_msgs_generate_messages_py [ 22%] Built target rosgraph_msgs_generate_messages_lisp [ 22%] Built target rosgraph_msgs_generate_messages_cpp [ 22%] [ 22%] Built target dynamic_reconfigure_gencfg [ 33%] Built target pid_gencfg [ 33%] Built target std_msgs_generate_messages_cpp Built target dynamic_reconfigure_generate_messages_cpp [ 33%] Built target dynamic_reconfigure_generate_messages_lisp [ 33%] Built target diagnostic_msgs_generate_messages_cpp [ 33%] [ 33%] Built target diagnostic_msgs_generate_messages_lisp Built target diagnostic_msgs_generate_messages_py [ 44%] [ 55%] Built target autotune Built target setpoint_node [ 66%] Built target plant_sim [ 77%] Built target controller [ 88%] Built target sim_time CMakeFiles/myopencvtest.dir/src/myopencvtest.cpp.o: In function main': myopencvtest.cpp:(.text+0x46e): undefined reference to cv::CommandLineParser::CommandLineParser(int, char const* const*, cv::String const&)' myopencvtest.cpp:(.text+0x4aa): undefined reference to cv::CommandLineParser::has(cv::String const&) const' myopencvtest.cpp:(.text+0x54c): undefined reference to cv::CommandLineParser::printMessage() const' myopencvtest.cpp:(.text+0x8e5): undefined reference to cv::namedWindow(cv::String const&, int)' myopencvtest.cpp:(.text+0x91c): undefined reference to cv::namedWindow(cv::String const&, int)' myopencvtest.cpp:(.text+0x958): undefined reference to cv::setMouseCallback(cv::String const&, void (*)(int, int, int, int, void*), void*)' myopencvtest.cpp:(.text+0x9bb): undefined reference to cv::createTrackbar(cv::String const&, cv::String const&, int*, int, void ()(int, void), void*)' myopencvtest.cpp:(.text+0xa2d): undefined reference to cv::createTrackbar(cv::String const&, cv::String const&, int*, int, void (*)(int, void*), void*)' myopencvtest.cpp:(.text+0xa9f): undefined reference to cv::createTrackbar(cv::String const&, cv::String const&, int*, int, void ()(int, void), void*)' myopencvtest.cpp:(.text+0xff0): undefined reference to cv::normalize(cv::_InputArray const&, cv::_InputOutputArray const&, double, double, int, int, cv::_InputArray const&)' myopencvtest.cpp:(.text+0x12b4): undefined reference to cv::rectangle(cv::InputOutputArray const&, cv::Point, cv::Point_, cv::Scalar_ const&, int, int, int)' myopencvtest.cpp:(.text+0x176c): undefined reference to cv::ellipse(cv::_InputOutputArray const&, cv::RotatedRect const&, cv::Scalar_<double> const&, int, int)' myopencvtest.cpp:(.text+0x18aa): undefined reference to cv::imshow(cv::String const&, cv::_InputArray const&)' myopencvtest.cpp:(.text+0x190e): undefined reference to cv::imshow(cv::String const&, cv::_InputArray const&)' myopencvtest.cpp:(.text+0x1a09): undefined reference to cv::destroyWindow(cv::String const&)' myopencvtest.cpp:(.text+0x1a42): undefined reference to cv::namedWindow(cv::String const&, int)' myopencvtest.cpp:(.text+0x1b39): undefined reference to cv::CommandLineParser::~CommandLineParser()' myopencvtest.cpp:(.text+0x1b78): undefined reference to cv::CommandLineParser::~CommandLineParser()' myopencvtest.cpp:(.text+0x218b): undefined reference to cv::CommandLineParser::~CommandLineParser()' CMakeFiles/myopencvtest.dir/src/myopencvtest.cpp.o: In function cv::String::String(char const*)': myopencvtest.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4f): undefined reference to cv::String::allocate(unsigned long)' CMakeFiles/myopencvtest.dir/src/myopencvtest.cpp.o: In function cv::String::~String()': myopencvtest.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to cv::String::deallocate()' CMakeFiles/myopencvtest.dir/src/myopencvtest.cpp.o: In function int cv::CommandLineParser::get<int>(int, bool) const': myopencvtest.cpp:(.text._ZNK2cv17CommandLineParser3getIiEET_ib[_ZNK2cv17CommandLineParser3getIiEET_ib]+0x36): undefined reference to cv::CommandLineParser::getByIndex(int, bool, int, void*) const' collect2: error: ld returned 1 exit status make[2]: *** [/home/bbick/ros_ws/devel/lib/inmoovhead/myopencvtest] Error 1 make[1]: *** [inmoovhead/CMakeFiles/myopencvtest.dir/all] Error 2 make: *** [all] Error 2 Invoking "make -j6 -l6" failed ==== End of catkin_make output

So it appears to NOT find the C++ libraries that are required for this to link. And here's my CMakeLists.txt: (With most commented out stuff removed for brevity)

make_minimum_required(VERSION 2.8.3) project(inmoovhead)

find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs message_generation )

################################################

Declare ROS messages, services and actions

################################################

Generate messages in the 'msg' folder

add_message_files( FILES Num.msg )

################################################

Declare ROS dynamic reconfigure parameters

################################################

###################################

catkin specific configuration

###################################

The catkin_package macro generates cmake config files for your package

Declare things to be passed to dependent projects

INCLUDE_DIRS: uncomment this if you package contains header files

LIBRARIES: libraries you create in this project that dependent projects also need

CATKIN_DEPENDS: catkin_packages dependent projects also need

DEPENDS: system dependencies of this project that dependent projects also need

catkin_package(

INCLUDE_DIRS include

LIBRARIES inmoovhead

CATKIN_DEPENDS roscpp rospy std_msgs

DEPENDS system_lib

CATKIN_DEPENDS message_runtime )

###########

Build

###########

Specify additional locations of header files

Your package locations should be listed before other locations

include_directories(include)

include_directories( ${catkin_INCLUDE_DIRS} )

Declare a C++ library

add_library(${PROJECT_NAME} # src/${PROJECT_NAME}/inmoovhead.cpp

)

Add cmake target dependencies of the executable

same as for the library above

add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

Specify libraries to link a library or executable target against

target_link_libraries(${PROJECT_NAME}_node # ${catkin_LIBRARIES}

)

Add folders to be run by python nosetests

catkin_add_nosetests(test)

find_package(OpenCV) include_directories(include ${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})

add_executable(myopencvtest src/myopencvtest.cpp)

target_link_libraries(myopencvtest ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})

add_dependencies(myopencvtest myopencvtest_generate_messages_cpp)

===== End of CMakeLIsts.txt

What am I missing to get the required libraries to be found? My opencv libs are in /usr/local/lib

Thanks, Burt


Originally posted by burtbick on ROS Answers with karma: 201 on 2017-04-23

Post score: 0


Original comments

Comment by mohsen1989m on 2017-04-23:
Please add your CMakeList.txt so people can help you.

Comment by Geoff on 2017-04-23:
I ran a cut-down version of your CMakeLists.txt on the first OpenCV sample (contours2.cpp), and it compiled fine. Please post your source files and the complete output of catkin_make so we can see what values it is finding when it searches for OpenCV.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I had pasted in the CMakeLIsts.txt file contents, just removed most of the commented lines to try and keep it brief, but it looks like the editor here mucked it up, or there is some different way to enter the code that cleans it up.

So..

Here's a link to the CMakeLists.txt file (renamed to BBCMakeLists.txt, only for this download)

My CMakeLists.txt

And to the OpenCV sample that I've enhanced to track my robot head. Note that this sample DOES not have the ROS code in but it has the same linking errors as my full application. Note also that I built the version of the app that integrates with ROS externally and it runs fine with ROS, and I have my head tracking well. But it won't link when built with the ROS build system using catkin_make. Other OpenCV tests I've done HAVE built and linked OK with catkin_make.

My Sample C++ File

Here's the only output I get from catkin_make, note I did a catkin_make clean first and then catkin_make

Since pasting the catkin_make output also seems to jumble up, here's a link to the output that I get:

catkin_make output

You should be able to download the files with no problems, but let me know if there is a problem.

Thanks, Burt


Originally posted by burtbick with karma: 201 on 2017-04-23

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by Geoff on 2017-04-24:
You need to delete the build/ and devel/ directories before running catkin_make, otherwise the configure step is skipped. Delete those two directories, then run VERBOSE=1 catkin_make and post the output.

Comment by Geoff on 2017-04-24:
Your code compiled fine for me, by the way.

Comment by burtbick on 2017-04-25:
Thanks Geoff,

I deleted build and devel and when I was building to gather the catkin_make output for you it built cleanly!!! The only thing I had done differently was deleting build and devel directory trees. So there must have been something in the old trees that was causing the problem.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.