我无法让Cmake工作。我正在使用ROS和catkin_make。我看过以下内容:
Parent.SetChildIndex
cmake undefined reference to function
但似乎仍无法将其编译。我正在尝试对我的代码使用Google单元测试。我是cmake和google测试的新手。我相信我错过了一些非常小而且显而易见的事情 我在一个文件“test_usbl.cpp”和一个应该调用我所有测试的主文件中进行测试。
这是我的档案:
usbl
├── CMakeLists.txt
├── CMakeLists.txt~
├── include
│ └── usbl
│ └── usblSim.h
├── package.xml
├── src
│ ├── usblSim.cpp
│ └── usblSim.cpp~
└── test
├── test_main.cpp
└── test_usbl.cpp
这是我的CMakeList.txt:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.3)
PROJECT(usbl)
SET(CMAKE_CXX_FLAGS "-g -std=c++0x ${CMAKE_CXX_FLAGS}")
FIND_PACKAGE(catkin REQUIRED COMPONENTS
geometry_msgs
roscpp
std_msgs
)
FIND_PACKAGE(GTest REQUIRED)
FIND_PACKAGE(Boost)
FIND_PACKAGE(Threads)
catkin_package( )
SET(INCLUDE_DIRS
${GTEST_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${catkin_INCLUDE_DIRS}
include/usbl
)
INCLUDE_DIRECTORIES(${INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../include/usbl)
SET(SRC
${CMAKE_CURRENT_SOURCE_DIR}/src/usblSim.cpp}
)
SET(LIBS
${ROS_LIBRARIES}
${catkin_LIBRARIES}
${Boost_LIBRARIES}
${GTEST_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
# simulator
#ADD_EXECUTABLE(usblSim src/usblSim.cpp)
add_library(usbl src/usblSim.cpp)
#TARGET_LINK_LIBRARIES(usblSim ${LIBS})
SET(USBL_TEST
test/test_usbl.cpp
test/test_main.cpp
)
ADD_EXECUTABLE(test_usbl ${USBL_TEST})
TARGET_LINK_LIBRARIES(test_usbl ${LIBS})
这给了我错误:
CMakeFiles/test_usbl.dir/test/test_usbl.cpp.o: In function `meanTest_isEquel_Test::TestBody()':
/home/nathaniel/Documents/usbl/src/usbl/test/test_usbl.cpp:12: undefined reference to `usblSim::usblSim()'
答案 0 :(得分:0)
找到解决方案,不得不做到:
SET(LIBS
${ROS_LIBRARIES}
${catkin_LIBRARIES}
${Boost_LIBRARIES}
${GTEST_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${PROJECT_NAME}#This is the new line
)