Boost::Thread and ROS Fuerte CMake help
Ok, so I am trying to utilize boost threads in a ROS application and I have been trying to figure out how to link boost to the the final exe. I keep finding conflicting ways on how to do this and not sure if i am doing it right.
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)
find_package(Boost REQUIRED COMPONENTS thread)
rosbuild_add_boost_directories()
#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(Joystick src/CJoystick.cpp)
rosbuild_add_library(Frame src/CFrame.cpp)
rosbuild_add_library(Control src/CControl.cpp)
rosbuild_add_library(Vec2 src/Classes/Vec2/Vec2.cpp)
rosbuild_add_library(Vec3 src/Classes/Vec3/vec3.cpp)
rosbuild_add_library(Vec4 src/Classes/Vec4/Vec4.cpp)
rosbuild_add_library(Mat3 src/Classes/Mat3/mat3.cpp)
rosbuild_add_library(Waypoint src/Classes/Waypoint/waypoint.cpp)
rosbuild_add_library(UAV src/Classes/UAV/UAV.cpp)
#rosbuild_add_library(ARDrone src/ARDrone.cpp)
rosbuild_add_executable(ARDroneV4 src/ARDrone.cpp)
target_link_libraries(ARDroneV4 UAV Waypoint Frame Control Mat3 Vec2 Vec3 Vec4 Joystick)
rosbuild_link_boost(ARDroneV4 thread system)
Though it compiles fine the threading never happens. Any idea on what I am doing wrong?
Update:
This is the basic outline . Everything not associated with the thread is not included.
#include <boost/thread.hpp>
void workfunc(){
ROS_INFO("New Thread");
}
int main(int argc,char **argv)
{
time_t rawtime;
std::string logfile;
ros::init(argc,argv, "ARDroneControl"); //create node
ros::NodeHandle n;
ros::Rate rate(FREQ); //cycle per seconds
while(n.ok())
{
boost::thread(workfunc);
ros::spinOnce();
rate.sleep();
}
return 0;
}
If it complies fine and you get no error when you create a boost::thread object then the problem does not lie in the linking of the library. To check if the library is linked properly you can type in the terminal: ldd ARDroneV4 | grep boost.
This is the output I get
and so forth.
I didn't think it was a linker problem but not even a simple function that prints "Hello World" doesn't print to screen. So I am not too sure what's going on then.
Then I suggest you update your question with a simple example which prints hello world in a new thread, so we might understand what is going wrong.
I updated it