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

Adding lines into CMakeList.txt makes an error. I need help

asked 2020-03-23 13:52:55 -0600

Karandiru gravatar image

updated 2020-03-25 13:26:13 -0600

Hello,

Firstly i need to say im totally beginner on ROS.I managed to install it and my Professor wanted to me complete these tasks;

-Create a ROS package with your name.

-Create two nodes, a chatter which publishes std_msgs and a listener to listen to chatter.

-The message you are required to send will be assigned for each one separately.

-The listener should get the message and print it using ROS_INFO function.

So i managed to create work space , but i stucked at somewhere that wants me to add these lines into my_package/CMakeLists.txt.

lines are ;

add_executable(name_of_node_chatter src/01.cpp) ,
target_link_libraries(name_of_node_chatter ${catkin_LIBRARIES}) , 
add_dependencies(name_of_node_chatter my_package_generate_messages_cpp)

link text

But when i add them into CMakeList.txt like this ; link text

After i save this txt file i try to run catkin_make command on terminal.It gaves me this error ; link text

I don't know what to do , please can you help me to fix this problem.

edit retag flag offensive close merge delete

Comments

Hi, the target you want to build is name_of_node_listener or name_of_node_chatter? In the screenshot of CMakeLists.txt you shared, it's written name_of_node_listener but here you wrote name_of_node_listener. Could you please add your entire CMakeLists.txt to your main question text? You can use the edit button/link for that. It would be easier for people to review. Thank you.

karenchiang gravatar image karenchiang  ( 2020-03-24 19:37:12 -0600 )edit

I guess i made huge mistake , without defining the chatter , i put listener code on CMakeList.txt that is why terminal gives me that 01.cpp error. In this case 01.cpp is chatter and 02.cpp is listener one.And im trying to run the code without chatter.Thank you for your answer. @tcchiang and also @nkhedekar

Karandiru gravatar image Karandiru  ( 2020-03-24 19:53:39 -0600 )edit
2

@tcchiang can you please update your question with a copy and paste of the errors instead of using images? Please see the Support page.

jayess gravatar image jayess  ( 2020-03-24 20:07:19 -0600 )edit

@jayess, I'm sorry but I am not the original poster. Please tag @Karandiru, thanks.

karenchiang gravatar image karenchiang  ( 2020-03-25 02:24:39 -0600 )edit

@tcchiang Sorry about that. @Karandiru can you please update your question with a copy and paste of the errors instead of using images?

jayess gravatar image jayess  ( 2020-03-25 02:50:02 -0600 )edit

I can not access to the ubuntu right now that is why i can not copy the errors from terminal.I editted the lines.Problem is still same. @jayess

Karandiru gravatar image Karandiru  ( 2020-03-25 13:30:14 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2020-03-25 16:47:17 -0600

updated 2020-03-26 06:38:43 -0600

Hello,

You should have added those three lines after find_package(). The order does matter in CMakeLists.txt. Please see wiki/catkin - CMakeLists.txt - Overall Structure and Ordering.

I think your package does not contain any messages/services/actions files so you don't really need

add_dependencies(name_of_node_chatter my_package_generate_messages_cpp)

If you do, you need to add generate_messages(DEPENDENCIES ...). The message generation targets are created by generate_messages(DEPENDENCIES ...). Using add_dependencies(name_of_node_chatter my_package_generate_messages_cpp) is to ensure that my_package_generate_messages_cpp is built before the name_of_node_chatter target.

If your target depends on other messages/services/actions from other packages, even though your package doesn't build any messages/services/actions at compile time, you should add

add_dependencies(name_of_node_chatter ${catkin_EXPORTED_TARGETS})

More details about add_dependencies(...) can be found here.

I think it's always safe to add a dependency on catkin_EXPORTED_TARGETS.

edit flag offensive delete link more

Comments

Hello ,

First of all thank your for your explanatory answer.But eventho i tried with your instructions , terminal gave me another error I dont know how to post a terminal output like a link but this is my CMakeList file i put lines in order like you said link text and this is terminal output of catkin_makelink text i hope you can still help me.

Karandiru gravatar image Karandiru  ( 2020-03-28 14:11:35 -0600 )edit

Hello, You shouldn't have added the lines inside the find_package() function. I couldn't tell you exactly where you should have added because you didn't show the whole contents of CMakeList.txt. If you are using the auto-generated CMakeLists.txt, then they should be added after include_directories(...). I strongly suggest you really look through this and this.

karenchiang gravatar image karenchiang  ( 2020-03-28 15:47:36 -0600 )edit

You don't need to post a terminal output as a link. Please copy-paste the terminal error messages and the CMakeList.txt into your original question, select the lines, and press ctrl+k or click the preformatted text button (the one with 101010 on it).

karenchiang gravatar image karenchiang  ( 2020-03-28 15:48:39 -0600 )edit
1

answered 2020-03-24 18:18:43 -0600

nkhedekar gravatar image

The error is probably due to having the incorrect ordering of your declarations. The lines that you mention should be added in the BUILD section (it should be somewhere around line #100) in the autogenerated CMakeLists.txt file.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-03-23 13:51:05 -0600

Seen: 225 times

Last updated: Mar 26 '20