cmake - ros - 如何包含boost(C ++)

时间:2017-05-30 13:28:48

标签: c++ boost cmake ros

我有一个ROS-JADE项目编译好。但是,当我启动启动文件时,我遇到了两个主要错误:

rtkrcv_node: /usr/include/boost/optional/optional.hpp:631: 
boost::optional<T>::reference_type boost::optional<T>::get() [with T = 
SolutionData; boost::optional<T>::reference_type = SolutionData&]: Assertion 
`this->is_initialized()' failed. 


***** Internal Program Error - assertion (i < N) failed in T& boost::array<T, 
N>::operator[](boost::array<T, N>::size_type) [with T = double; long unsigned
 int N = 2000ul; boost::array<T, N>::reference = double&; boost::array<T, 
N>::size_type = long unsigned int]: 
/usr/include/boost/array.hpp(123): out of range 

在我的.hpp文件的程序中,我使用以下的boost库:

升压::阵列
升压::可选

我认为上面的这两个错误是由于我没有使用我的CMakeLists.txt文件正确构建我的代码。目前我主要做以下几点来构建我的两个节点:

include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})
add_executable(rviz_node
src/rviz_sub.cpp)
add_dependencies(rviz_node ${catkin_EXPORTED_TARGETS})
target_link_libraries(rviz_node
 ${catkin_LIBRARIES}
m
rt
pthread
)

add_definitions(-DENAGLO -DENAGAL -DENACMP -DENAQZS -DNFREQ=6 -DTRACE -DNEXOBS=3)
add_executable(rtkrcv_node
  src/main.cpp
  src/ros_options.cpp
  src/rtkrcv.cpp
)
add_dependencies(rtkrcv_node ${catkin_EXPORTED_TARGETS})
target_link_libraries(rtkrcv_node
  ${catkin_LIBRARIES}
  m
  rt
  pthread
)

我还尝试包含了boost库,但我还没有尝试过。 我的Boost版本是1.54.0 我遇到了与此处宣布的相同的问题(Could not find the following Boost libraries: boost_asio),因为我也想使用Array和Optional Boost lib .... 但是,如果我尝试例如:

    find_package(Boost 1.54.0 REQUIRED system)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})
add_executable(rviz_node
src/rviz_sub.cpp)
add_dependencies(rviz_node ${catkin_EXPORTED_TARGETS})
target_include_directories(rviz_node PRIVATE ${Boost_INCLUDE_DIRS})
target_link_libraries(rviz_node
 ${Boost_LIBRARIES}
 ${catkin_LIBRARIES}
m
rt
pthread
)

根据第一个错误的进一步细节: 我的rtkrcv.cpp文件如下所示:

...
boost::optional<SolutionData> getSolution () {
  boost::optional<SolutionData> data; 
....
}

我的rtkrcv.hpp文件如下:

#include <boost/optional.hpp>
...
boost::optional<SolutionData> getSolution ();
struct SolutionData {
...
};

在我的main.cpp中,我执行以下操作:

...
 auto sol = getSolution(); // opens rtkrcv.cpp
...
...

0 个答案:

没有答案