Ask Your Question
4

undefined reference to `ros::init(int&, char**, std::string const&, unsigned int)'

asked 2015-11-06 23:05:17 -0500

cybodroid gravatar image

updated 2015-11-07 18:16:58 -0500

Hi,

I was trying to build ros package but while doing catkin_make, I am getting error

undefined reference to `ros::init(int&, char**, std::string const&, unsigned int)'

I followed the tutorial exactly as mentioned on Markers: Sending Basic Shapes (C++) but still I am not able to build the package. I looked up online but most of forums state the problems which is not present with my code.

While creating package I used command:

catkin_create_pkg using_markers roscpp visualization_msgs

I have added target_link_libraries(basic_shapes ${catkin_LIBRARIES}) in CMakeLists.txt as well. In spite of that, I am getting undefined reference.

Note: I am using Jade distribution of ROS.

Edit: Content of CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(using_markers)

add_executable(basic_shapes src/basic_shapes.cpp)
target_link_libraries(basic_shapes ${catkin_LIBRARIES})

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  roscpp
  visualization_msgs
)

###################################
## 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 using_markers
#  CATKIN_DEPENDS roscpp visualization_msgs
#  DEPENDS system_lib
)

###########
## Build ##
###########

## Specify additional locations of header files
## Your package locations should be listed before other locations
# include_directories(include)
include_directories(
  ${catkin_INCLUDE_DIRS}
)

Any insight in this regard will be helpful.

Thanks.

edit retag flag offensive close merge delete

Comments

It would be helpful if you can post your CMakeLists.txt file content.

Akif gravatar image Akif  ( 2015-11-07 04:44:41 -0500 )edit

I have edited question details and added the content of CMakeLists.txt

cybodroid gravatar image cybodroid  ( 2015-11-07 18:17:27 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
8

answered 2015-11-07 18:48:05 -0500

ahendrix gravatar image

updated 2015-11-07 18:48:40 -0500

Your CMakeLists is not in the correct order; you define your executable and add libraries before you indicate which libraries to link to; this results in not linking to any libraries. (unfortunately, cmake does not warn you if you use a variable before it is defined).

You should reorder you cmakelists so that the calls to find_package(catkin ...), catkin_package(...) and include_directories() come before any calls to add_executable(), add_library() or target_link_libraries().

edit flag offensive delete link more

Comments

Hey. Thanks for the help. You pointed out rightly and it worked.

cybodroid gravatar image cybodroid  ( 2015-11-07 19:00:54 -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: 2015-11-06 23:05:17 -0500

Seen: 16,488 times

Last updated: Nov 07 '15