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

How to rosmake project with c and cpp?

asked 2014-03-03 13:02:37 -0500

ZiyangLI gravatar image

updated 2014-03-03 19:17:47 -0500

Hi all,

I am making a project with c and cpp involved. For example, in the src folder I have:

a.h a.cpp -- main function

b.h b.c -- some utility functions

How can I modified the CMakeList.txt to make it work? I get errors saying that a.cpp has undefined reference to some functions, which are defined in b.c, while I already include b.h in a.h. My current CMakeList.txt looks like this.

rosbuild_add_library(mylib src/b.c)
rosbuild_add_executable(mymain src/a.cpp)
target_link_libraries(mymain mylib)

I have not solved the problem with ROS rosmake yet. But I add the following lines in a makefile and use nomal make command and it works.

# The pre-processor options used by the cpp (man cpp for more).
CPPFLAGS  = -Wall -I/opt/ros/fuerte/include/

# The options used in linking as well as in any direct use of ld.
LDFLAGS   = -L/opt/ros/fuerte/lib/ -lopencv_core -lopencv_imgproc -lopencv_highgui
edit retag flag offensive close merge delete

Comments

those 3 cmake lines look OK

brice rebsamen gravatar image brice rebsamen  ( 2014-03-03 15:11:47 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-03-03 13:14:55 -0500

PKG gravatar image

updated 2014-03-03 13:50:47 -0500

(Long comment) First of all there seems to be a basic linker error, which is giving you the message about undefined functions. This means that no matter what make system you use, you're going to get the same error. This is generic and not ROS-specific. I suggest looking at resources like these first to nip this issue in the bud.

Once this is sorted out, get a hang of how CMake works first. I also suggest using Catkin to build instead of rosbuild, which uses rosmake. Then, go to catkin docs to get an idea of how the catkin build tool works on ROS.

Keep in mind: the basic build system is the GNU Make, on Unix and Linux systems. CMake is an abstraction that generates Makefiles. Catkin is yet another abstraction over CMake.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-03-03 13:02:37 -0500

Seen: 235 times

Last updated: Mar 03 '14