我有以下CMakeLists文件: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實際上知道函數的位置,但是當我嘗試運行時,只是簡單地找不到它。有任何想法嗎?
問候
CMake 2.6版本不支持'target_link_libraries'。上述CMake文件至少需要2.8.11版本。也就是說,我建議你將它升至3.6或3.7,並[開始編寫現代CMake](https://rix0r.nl/blog/2015/08/13/cmake-guide/)。 – tambre