Я использовал CMake для сборки своего проекта и Catch2 для тестирования. Ниже приведена структура моего проекта
├── build
├── CMakeLists.txt
├── compile_commands.json
├── include
│ ├── node.h
│ ├── rrt.h
│ └── tree.h
├── Makefile
├── package.xml
├── scripts
├── src
│ ├── main.cpp
│ ├── node.cpp
│ ├── rrt.cpp
│ └── tree.cpp
├── test
│ ├── CMakeLists.txt
│ └── test.cpp
└── third_party
└── catch.hpp
В ./CMakeLists.txt
:
cmake_minimum_required(VERSION 2.8.3)
project(rrt_ros)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/include/rrt.h
${CMAKE_CURRENT_SOURCE_DIR}/include/tree.h
${CMAKE_CURRENT_SOURCE_DIR}/include/node.h
${CMAKE_CURRENT_SOURCE_DIR}/src/rrt.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/tree.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/node.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
)
find_package(catkin REQUIRED COMPONENTS roscpp std_msgs)
find_package(Armadillo REQUIRED)
FIND_PACKAGE(Eigen3 REQUIRED)
add_executable(
rrt
${SOURCES}
)
target_include_directories(
rrt
PUBLIC
${catkin_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR}
${ARMADILLO_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_link_libraries(rrt ${catkin_LIBRARIES} ${ARMADILLO_LIBRARIES})
add_subdirectory(test)
В test/CMakeLists.txt
, у меня
project(rrt_ros)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(catkin REQUIRED COMPONENTS roscpp std_msgs)
find_package(Armadillo REQUIRED)
FIND_PACKAGE(Eigen3 REQUIRED)
message("TESTING......" ${CMAKE_CURRENT_SOURCE_DIR}/../include/rrt.h)
add_executable(rrt_test test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../include/rrt.h
${CMAKE_CURRENT_SOURCE_DIR}/../include/tree.h
${CMAKE_CURRENT_SOURCE_DIR}/../include/node.h
${CMAKE_CURRENT_SOURCE_DIR}/../src/rrt.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../src/tree.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../src/node.cpp
)
target_include_directories(
rrt_test
PUBLIC
${catkin_INCLUDE_DIRS}
${Armadillo_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../third_party
${CMAKE_CURRENT_SOURCE_DIR}/../include
)
target_link_libraries(
rrt_test
${catkin_LIBRARIES}
${Aramdillo_LIBRARIES}
)
В rrt.cpp
у меня есть функция, которая вызывает функцию выборки броненосца
arma::randi<arma::mat>(1, 2, arma::distr_params(1, 10))
Когда я компилирую проект, он дает мне неопределенную ошибку:
rrt.cpp:(.text._ZTWN4arma23arma_rng_cxx11_instanceE[_ZTWN4arma23arma_rng_cxx11_instanceE]+0x15): undefined reference to 'arma::arma_rng_cxx11_instance'
collect2: error: ld returned 1 exit status
Однако, когда я комментирую ${CMAKE_CURRENT_SOURCE_DIR}/../src/rrt.cpp
в ./test/CMakeLists.txt
, он компилируется нормально.