体系结构的未定义符号 x86_64:"vtkDebugLeaksManager::vtkDebugLeaksManager()",引用自:

Undefined symbols for architecture x86_64: "vtkDebugLeaksManager::vtkDebugLeaksManager()", referenced from:

我在构建包含 c pcl_visualizer.h 的简单 .cpp 文件时遇到了以下异常。仅包含!

建筑物IDECLion

[ 50%] Building CXX object CMakeFiles/untitled2.dir/main.cpp.o
[100%] Linking CXX executable untitled2
Undefined symbols for architecture x86_64:
  "vtkDebugLeaksManager::vtkDebugLeaksManager()", referenced from:
      ___cxx_global_var_init.3 in main.cpp.o
  "vtkDebugLeaksManager::~vtkDebugLeaksManager()", referenced from:
      ___cxx_global_var_init.3 in main.cpp.o
  "vtkObjectFactoryRegistryCleanup::vtkObjectFactoryRegistryCleanup()", referenced from:
      ___cxx_global_var_init.4 in main.cpp.o
  "vtkObjectFactoryRegistryCleanup::~vtkObjectFactoryRegistryCleanup()", referenced from:
      ___cxx_global_var_init.4 in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [untitled2] Error 1
make[2]: *** [CMakeFiles/untitled2.dir/all] Error 2
make[1]: *** [CMakeFiles/untitled2.dir/rule] Error 2

这是我的CMakeLists.txt配置

cmake_minimum_required(VERSION 3.14)
project(untitled2)

include_directories(
        "/usr/local/include/pcl-1.9"
        "/usr/local/include/eigen3"
        "/usr/local/include/vtk/8.2.0"
        "/usr/local/include/flann/"
        "/usr/local/Cellar/boost/1.71.0/include"
        "/usr/local/Cellar/vtk/8.2.0_3/include/vtk-8.2"
)

link_directories(
        "/usr/local/lib/"
)
set(CMAKE_CXX_STANDARD 17)
add_executable(untitled2 main.cpp)

CMakeLists.txt不需要那么冗长、脆弱。此外,您没有链接库,只是指定要搜索的路径。

Docs for link_directories 正如文档中所说,这是不好的做法,因为 find_package 应该为您完成所有这些工作。

您需要指定 target_link_libraries 才能找到符号。

我使用以下 (link to repo):

cmake_minimum_required(VERSION 3.5)
project(pcl_cmake_minimum)

find_package(PCL COMPONENTS common)

add_executable(pcl_demo main.cpp)

target_link_libraries(pcl_demo ${PCL_LIBRARIES})