ROS and CMake help with linking
Ok, so I made a mistake by including .cpp files instead of the .h files of my classes in my project. The problem I am having is after fixing it to the right way, including the .h and not the .cpp, I am getting linking errors.
I am not sure if I am doing this right though but I am trying to link the classes to the project but keep getting a undefined reference when at the linking stage of cmake.
This is my CMAKE file:
cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
# Set the build type. Options are:
# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage
# Debug : w/ debug symbols, w/o optimization
# Release : w/o debug symbols, w/ optimization
# RelWithDebInfo : w/ debug symbols, w/ optimization
# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries
#set(ROS_BUILD_TYPE RelWithDebInfo)
rosbuild_init()
#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
#uncomment if you have defined messages
#rosbuild_genmsg()
#uncomment if you have defined services
#rosbuild_gensrv()
#common commands for building c++ executables and libraries
#rosbuild_add_library(${PROJECT_NAME} src/ARDroneV3.cpp)
rosbuild_add_library(${PROJECT_NAME} src/Classes/Vec4/Vec4.cpp)
rosbuild_add_library(${PROJECT_NAME} src/Classes/Mat3/mat3.cpp)
rosbuild_add_library(${PROJECT_NAME} src/Classes/Vec2/Vec2.cpp)
target_link_libraries(src/Classes/Vec4/)
target_link_libraries(src/Classes/Mat3/)
target_link_libraries(src/Classes/Vec2/)
#rosbuild_add_boost_directories()
#rosbuild_link_boost(${PROJECT_NAME} thread)
#rosbuild_add_executable(src/ARDroneV3.cpp)
#target_link_libraries(example ${PROJECT_NAME})
rosbuild_add_executable(ARDroneV3 src/ARDrone.cpp src/CJoystick.cpp src/CFrame.cpp src/CControl.cpp)
Any help will be appreciated and please go easy, I am new to CMAKE so still trying to learn it. Thanks for any and all help.
Update:
The lab I'm at is using Fuerte on Ubuntu 12.04
The errors is a undefined reference to Mat3, Vec3, Vec4 and Vec2. If I do it the wrong way by including the .cop file it works buy doing the right way I get the undefined reference error while linking.
Update part duex I guess my description to my error was a bit ambigious, so this is one of the errors. You will get the point as it applies to all the classes that I created that were mentioned (Mat3,Vec3..and so on)
In function `CControl::Hover()':
/UAV/ARDroneV3/src/CControl.cpp:63: undefined reference to `Vec4<float>::setA(float const&)'
Update part Three
After some googling I found out it was how the compiler was handling templated classes. I went ahead and found this Solution. I went with answer one and it works fine since I know how the classes will be used.
After doing that I added the .cpp files to the rosbuld_add_excutable directive while commenting out the eronous things above. Works like a charm now.
rosbuild_add_executable(ARDroneV3 src/ARDrone.cpp src/CJoystick.cpp src/CFrame.cpp src/CControl.cpp src/Classes/Vec4/Vec4.cpp src/Classes/Mat3/mat3.cpp src/Classes/Vec2/Vec2.cpp src/Classes/Vec3/vec3.cpp)
Could you please clarify a couple things for us? For example, it would be nice to know the exact linker error and the ros version. Please edit your question with this information. We can be much more helpful that way. :)
I edited it, hope it helps.