c++ - 体系结构 x86_64 : "vtkDebugLeaksManager::vtkDebugLeaksManager()", 的 undefined symbol 引用自:

标签 c++ c vtk point-cloud-library point-clouds

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

构建 IDE CLion

[ 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 不需要如此冗长、脆弱。此外,您没有链接库,只是指定要搜索的路径。 Related

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})

关于c++ - 体系结构 x86_64 : "vtkDebugLeaksManager::vtkDebugLeaksManager()", 的 undefined symbol 引用自:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58038409/

相关文章:

c++ - 在循环中使用 stringstream

c++ - Windows API 和管理员帐户的危险?

c - 为什么我会收到 lValue 错误?

python - 如何将 vtkPolyData 的 Polys 保存到数据库并将它们分配给 vtkPoints?

c++ - 读/写 vtk 文件显示不正确

c++ - UE4打开VS2017两次

c++ - 为什么 tm_sec 在 time.h 中的范围是 0-60 而不是 0-59?

c - fork() 从哪里开始

c - 数组初始值设定项必须是初始值设定项列表或宽字符串文字

linux - VTK 应用程序的可移植性