CMakeLists - Make找不到头文件

时间:2017-06-25 09:42:27

标签: c++ header include point-cloud-library

我有以下CMakeLists文件:

cmake_minimum_required(VERSION 2.6 FATAL_ERROR)

project(PointCloudComparator)

find_package(PCL 1.7 REQUIRED COMPONENTS common io)

set(PCL_DIR "/usr/share/pcl-1.7/PCLConfig.cmake")
set(PCL_INCLUDE_DIRS "/usr/include/pcl-1.7")
set(PCL_LIBRARY_DIRS "/usr/lib/")


include_directories(${PCL_INCLUDE_DIRS} "/usr/include/eigen3" "include")
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable (segmentator src/segmentation.cpp include/segmentation.h)
target_link_libraries (segmentator ${PCL_LIBRARIES} 
${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES} 
"/usr/lib/libpcl_visualization.so" "/usr/lib/libpcl_keypoints.so" 
"/usr/lib/libpcl_features.so" "/usr/lib/libpcl_kdtree.so" 
"/usr/lib/libpcl_search.so" "/usr/lib/libpcl_filters.so" 
"/usr/lib/libpcl_segmentation.so" 
"/usr/lib/libpcl_sample_consensus.so")

add_executable (comparator src/comparator.cpp include/comparator.h 
include/segmentation.h)
target_link_libraries (comparator ${PCL_LIBRARIES} 
${PCL_COMMON_LIBRARIES} 
${PCL_IO_LIBRARIES} "/usr/lib/libpcl_visualization.so" 
"/usr/lib/libpcl_keypoints.so" "/usr/lib/libpcl_features.so" 
"/usr/lib/libpcl_kdtree.so" "/usr/lib/libpcl_search.so" 
"/usr/lib/libpcl_filters.so" "/usr/lib/libpcl_segmentation.so" 
"/usr/lib/libpcl_sample_consensus.so")

但是,当我尝试编译代码时,我收到错误:

CMakeFiles/comparator.dir/src/comparator.cpp.o: In function `main':
comparator.cpp:(.text+0x3313): reference to 
`region_growing_segmentation(std::string)' not defined
collect2: error: ld returned 1 exit status

region_growing_segmentation(std :: string)是在segmentation.h中声明并在segmentation.cpp中定义的函数。 Eclipse实际上知道函数的位置,但是当我尝试运行时,它只是无法找到它。有什么想法吗?

此致

1 个答案:

答案 0 :(得分:1)

您正在构建两个单独的可执行文件(segmentatorcomparator)。每个可执行文件都由一个源文件和一个头文件组成。这就是你用add_executable命令所说的。单个add_executable命令使用的源文件与您创建的任何其他可执行目标共享。

如果您有两个程序之间应该共享的公共代码,那么您应该将它放在一个单独的源文件中,并将其添加到每个可执行文件中(将新的公共源文件添加到add_executable命令中)。或者创建一个与两个可执行文件链接的库目标。