使用cgal和pcl时的Linking误差提升

问题描述 投票:0回答:2

在项目中同时使用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 include时,程序运行良好,但是当我排除cgal include时,我得到了非常相似的错误:

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
2个回答
0
投票

我似乎找到了答案。 boost似乎存在问题,并且使boost库静态化可以解决该问题。 (我发现了关于同一问题的问题:C++ using two incompatible libraries together, what are the options?

因此,要解决此问题,请在CMake GUI中检查“高级”选项,然后在CGAL下检查CGAL_Boost_USE_STATIC_LIBS。


0
投票

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

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

请注意,在大多数情况下,链接错误表示target_link_libraries()有问题,可能是缺失或给定的值有误。

© www.soinside.com 2019 - 2024. All rights reserved.