【问题标题】:LInking error boost when using cgal and pcl使用 cgal 和 pcl 时的链接错误提升
【发布时间】:2020-08-31 12:45:05
【问题描述】:

在项目中同时使用 PCL 和 cgal 时出现 boost 链接错误(以及重新定义警告)。 PCL 和 cgal 示例都运行良好,因此安装应该很好。

我的测试程序如下所示:

#include <iostream>
#include <CGAL/Simple_cartesian.h>
#include <pcl/visualization/cloud_viewer.h>
int
main()
{
    std::cout << "Test "<< std::endl;
    return 0;
}

我得到的错误粘贴在下面:

1>------ Build started: Project: PC_Svr2, Configuration: Debug x64 ------
1>cloud_viewer.cpp
1>Unknown compiler version - please run the configure tests and report the results
1>C:\Program Files\PCL 1.8.1\include\pcl-1.8\pcl/visualization/boost.h(51,1): warning C4005: 'BOOST_PARAMETER_MAX_ARITY': macro redefinition
1>C:\dev\CGAL-5.0.2\include\CGAL/config.h(115): message : see previous definition of 'BOOST_PARAMETER_MAX_ARITY'
1>cloud_viewer.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class boost::system::error_category const & __cdecl boost::system::system_category(void)" (__imp_?system_category@system@boost@@YAAEBVerror_category@12@XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'native_ecat''(void)" (??__Enative_ecat@system@boost@@YAXXZ)
1>cloud_viewer.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (__imp_?generic_category@system@boost@@YAAEBVerror_category@12@XZ) referenced in function "public: __cdecl boost::thread_exception::thread_exception(int,char const *)" (??0thread_exception@boost@@QEAA@HPEBD@Z)
1>C:\Users\PCL_Project\PC_svr2\build\Debug\PC_Svr2.exe : fatal error LNK1120: 2 unresolved externals
1>Done building project "PC_Svr2.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========

当我排除 PCL 包含时,程序运行正常,但是当我排除 cgal 包含时,我得到一个非常相似的错误:

1>------ Build started: Project: PC_Svr2, Configuration: Debug x64 ------
1>cloud_viewer.cpp
1>Unknown compiler version - please run the configure tests and report the results
1>cloud_viewer.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class boost::system::error_category const & __cdecl boost::system::system_category(void)" (__imp_?system_category@system@boost@@YAAEBVerror_category@12@XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'native_ecat''(void)" (??__Enative_ecat@system@boost@@YAXXZ)
1>cloud_viewer.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (__imp_?generic_category@system@boost@@YAAEBVerror_category@12@XZ) referenced in function "public: __cdecl boost::thread_exception::thread_exception(int,char const *)" (??0thread_exception@boost@@QEAA@HPEBD@Z)
1>C:\Users\PCL_Project\PC_svr2\build\Debug\PC_Svr2.exe : fatal error LNK1120: 2 unresolved externals
1>Done building project "PC_Svr2.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========

我不确定,但我怀疑它可能与我的 CMakeLists.txt 有关,我也会将其粘贴在下面:

cmake_minimum_required(VERSION 3.1...3.15)
project(PC_Svr2)
find_package(CGAL QUIET)
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (PC_Svr2 cloud_viewer.cpp)
target_link_libraries(PC_Svr2 CGAL::CGAL ${PCL_LIBRARIES})

有人知道问题出在哪里吗?

【问题讨论】:

    标签: c++ boost linker-errors cgal


    【解决方案1】:

    我似乎找到了答案。这似乎是 boost 的一个问题,使 boost 库静态解决了这个问题。 (我发现这个问题关于同样的问题:C++ using two incompatible libraries together, what are the options?

    所以要修复它,请检查 CMake GUI 中的 Advanced 选项,然后在 CGAL 下检查 CGAL_Boost_USE_STATIC_LIBS。

    【讨论】:

      【解决方案2】:

      您在 CMakeLists.txt 中误解了 boost。您的测试在没有 PCL 的情况下运行良好,因为 CGAL 的标头不需要提升,我猜 PCL 需要。 您需要添加 find_package(Boost COMPONENTS system)target_link_libraries(PC_Svr2 CGAL::CGAL ${PCL_LIBRARIES} Boost::system)。 之后应该没问题。

      如果没有,请检查您需要哪些组件并相应地更改您的配置文件。

      请注意,大多数情况下,链接错误意味着target_link_libraries() 有问题,要么它丢失,要么给它的值错误。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-21
        • 2023-03-24
        • 2016-12-31
        • 1970-01-01
        • 2022-08-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多