2017-06-25 67 views
0

我有以下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實際上知道函數的位置,但是當我嘗試運行時,只是簡單地找不到它。有任何想法嗎?

問候

+0

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

回答

1

你需要建立兩個獨立的可執行文件(segmentatorcomparator)。每個可執行文件都由一個單獨的源文件和一個單獨的頭文件構成。這就是你說的add_executable命令。單個add_executable命令使用的源文件是而不是與您創建的任何其他可執行目標共享。

如果您有共享的代碼應該在兩個程序之間共享,那麼您應該將其添加到單獨的源文件中,並添加到每個可執行文件(將新的通用源文件添加到add_executable命令中)。或者創建一個與兩個可執行文件鏈接的庫目標。

+0

所以我只需要添加般的線條: add_library(MYLIB SHARED SRC/segmentation.cpp的src/comparator.cpp) set_property(TARGET MYLIB PROPERTY IMPORTED_LOCATION mylib.a上) 而MYLIB到兩個target_link_libraries? –

+0

像你說的那樣工作,我只是添加了一個鏈接到.cpp文件 的庫目標。謝謝 –