Reputation: 395
I have the following CMakeLists file:
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")
But, when I try to compile my code, I get the error:
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) is a function declared in segmentation.h and defined in segmentation.cpp. Eclipse actually knows where the function is but when I try to run make it just simply cant find it. Any ideas?
Regards
Upvotes: 0
Views: 162
Reputation: 409176
You are building two separate executables (segmentator
and comparator
). Each executable is made from one single source file and one single header file. That is what you say with the add_executable
commands. The source files used by a single add_executable
command is not shared with any other executable target you create.
If you have common code that should be shared between the two programs, then you should put it in a separate source file that you add to each executable (add the new common source file to the add_executable
command). Or create a library target that is linked with the two executables.
Upvotes: 1