Ask Your Question
1

Source Files failing to Build (C++ image subscriber tutorial)

asked 2014-11-21 15:17:55 -0500

ronpaul gravatar image

updated 2014-11-22 02:09:22 -0500

gvdhoorn gravatar image

Hi,

I'm new to ROS and have recently completed all of the tutorials in the tutorials section. I'm currently trying to get a C++ image subscriber working with our TurtleBot and I'm using the tutorial found here: http://wiki.ros.org/image_transport/T...

but as I follow the tutorial and try to build the node, the source files fail to build. From my experience with the tutorials I think it may be due to me not declaring the proper dependencies while making the package or in the CMakeLists.txt file (I don't know what they should be since it doesn't specify in the tutorial.)

I first create a new catkin package with the roscpp dependency while in ~/catkin_ws by typing the command: catkin_create_pkg image_transport_tutorial roscpp

After that, inside of the new "src" directory at ~/catkin_ws/src/image_transport_tutorial/src I paste the my_subscriber.cpp and my_publisher.cpp files I copied from the tutorial.

Here is probably where I go wrong: Inside of my CMakeLists.txt file in ~/catkin_ws/src/image_transport_tutorial/CMakeLists.txt I don't know exactly what to write to make the file executable since it doesn't specify in the tutorial, so I tried to craft a similar one to the example in the original "Writing a node in C++ for ROS" tutorial and the answer found here http://answers.ros.org/question/50953... . Here is what I added to the bottom of the file:

find_package(OpenCV REQUIRED)
add_executable(my_publisher src/my_publisher.cpp) 
target_link_libraries(my_publisher ${catkin_LIBRARIES})     
target_link_libraries(my_publisher ${OpenCV_LIBS})
add_dependencies(my_publisher image_transport_tutorial_generate_messages_cpp)

find_package(OpenCV REQUIRED)
add_executable(my_subscriber src/my_subscriber.cpp)
target_link_libraries(my_subscriber ${catkin_LIBRARIES})
target_link_libraries(my_subscriber ${OpenCV_LIBS})
add_dependencies(my_subscriber image_transport_tutorial_cpp)

I then navigate back to ~/catkin_ws and run catkin_make

This is the error message I get:

Scanning dependencies of target my_publisher Scanning dependencies of target my_subscriber
[ 7%] Building CXX object image_transport_tutorial/CMakeFiles/my_publisher.dir/src/my_publisher.cpp.o
[ 11%] Building CXX object image_transport_tutorial/CMakeFiles/my_subscriber.dir/src/my_subroslocate info create_gazebo_plugins --distro hydroscriber.cpp.o
/home/turtlebot/catkin_ws/src/image_transport_tutorial/src/my_publisher.cpp: In function ‘int main(int, char**)’:
/home/turtlebot/catkin_ws/src/image_transport_tutorial/src/my_publisher.cpp:13:16: error: ‘WaitKey’ was not declared in this scope
/home/turtlebot/catkin_ws/src/image_transport_tutorial/src/my_subscriber.cpp: In function ‘void imageCallback(const ImageConstPtr&)’:
/home/turtlebot/catkin_ws/src/image_transport_tutorial/src/my_subscriber.cpp:11:5: error: ‘WaitKey’ is not a member of ‘cv’
make[2]:
* [image_transport_tutorial/CMakeFiles/my_publisher.dir/src/my_publisher.cpp.o] Error 1
make[1]:
* [image_transport_tutorial/CMakeFiles/my_publisher.dir/all] Error 2
make[1]:
* Waiting for unfinished jobs....
make[2]:
* [image_transport_tutorial/CMakeFiles/my_subscriber.dir/src/my_subscriber.cpp.o] Error 1
make[1]:
* [image_transport_tutorial/CMakeFiles/my_subscriber.dir/all] Error 2
make:
* [all] Error 2 Invoking "make" failed

From what I understand, it look like it's not recognizing "cv", so perhaps the opencv dependencies aren't being imported?

Any help would be greatly appreciated.

Keep in mind that my only experience with ROS so far are the main ROS tutorials, so please be gentle and phrase your answers simply.

Thanks!

edit retag flag offensive close merge delete

Comments

Please have a look at your question preview before posting, your error had all of the newlines stripped out of it...

William gravatar image William  ( 2014-11-21 15:48:22 -0500 )edit

2 Answers

Sort by » oldest newest most voted
3

answered 2014-11-21 15:53:52 -0500

William gravatar image

The error appears to be in your code file my_publisher.cpp because WaitKey is not in the cv scope, which makes sense because it appears to be cv::waitKey in C++, see:

http://docs.opencv.org/modules/highgu...

I don't believe this has anything to do with your build files or ROS.

edit flag offensive delete link more
1

answered 2014-11-22 01:57:59 -0500

gvdhoorn gravatar image

updated 2014-11-22 02:10:23 -0500

In addition to what @William posted, some other comments:

  • perhaps it wasn't copy/pasted, but I don't see an

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

    anywhere, which could also be responsible for the not declared error.

  • you only need to find_package(OpenCV) once, the results get cached. Also, I'd add a REQUIRED to that, as your code can't compile without OpenCV being available.
  • you can link your targets to multiple (sets of) libraries with a single target_link_libraries(..) invocation. Just do:

    target_link_libraries(my_publisher ${OpenCV_LIBS} ${catkin_LIBRARIES})
    

    for the my_publisher target fi.

  • is image_transport_tutorial_cpp (from add_dependencies(my_subscriber ..)) an actual target from image_transport? Perhaps you meant image_transport_tutorial_gencpp (which is deprecated, afaik)?

Minor things, but they make your CMakeLists.txt a bit easier to read and maintain.

edit flag offensive delete link more

Comments

Yeah, I figured he was finding the headers otherwise there would have been an error about no such file for the #include, but all good additional points.

William gravatar image William  ( 2014-11-23 20:02:34 -0500 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-11-21 15:17:55 -0500

Seen: 1,115 times

Last updated: Nov 22 '14