undefined reference cmake [closed]

asked 2013-03-22 02:08:16 -0500

aps40 gravatar image

Hi,

I'm trying link my own library in ros, which .cpp is in lib folder and the .h is in include folder. My folder schema is:

-CMakeList.txt
-Build/
-src/
---- Program.cpp
-lib/
---- MyLib.cpp
-include/
---- MyLib.h

I have create the next cmake:

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

rosbuild_init()

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

find_package(PCL 1.6 REQUIRED)
message("PCL:" ${PCL_INCLUDE_DIRS})

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

rosbuild_add_library(MyLib lib/MyLib.cpp)

rosbuild_add_executable(Program src/Program.cpp)
target_link_libraries(Program MyLib ${PCL_LIBRARIES})

When I excute rosmake it show next error:

   src/Program.cpp:34: undefined reference to function....

The function that is not referenced is in MyLib, whoever rosmake has create libMyLib.o in lib folder.

If I writte the code of methods in MyLib.h instead of in MyLib.cpp I haven't this error.

Can anyone help me?

thanks

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2013-05-27 09:15:17

Comments

I can't see why off-hand, but why don't you post the results of CDing into the build folder and running "VERBOSE=1 make" (without quotes) - that should help anyone help you.

DamienJadeDuff gravatar image DamienJadeDuff  ( 2013-03-22 02:46:02 -0500 )edit

Also, I'm not sure how it could be relevant, but why don't you try moving MyLib.cpp out of the lib/ folder and into a different one, as lib/ normally receives the binary library files (e.g. MyLib.so).

DamienJadeDuff gravatar image DamienJadeDuff  ( 2013-03-22 03:10:50 -0500 )edit