【问题标题】:linking Boost to c++ project将 Boost 链接到 C++ 项目
【发布时间】:2018-08-19 12:20:47
【问题描述】:

我在使用 BOOST 库时遇到问题, 我下载了 boost_1_59_0 安装程序并将其安装到“C:\local\boost_1_59_0” 然后我添加了boost变量如下 click here

在使用 qt creator 或 visual studio 的 c++ 项目中包含 boost 时,它显示了很多错误

CGAL 示例:

#include <iostream>

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>

#include <CGAL/convex_hull_2.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;

typedef K::Point_2 Point_2;

int main()

{

    Point_2 points[5] = { Point_2(0,0), Point_2(10,0), Point_2(10,10),

    Point_2(6,5), Point_2(4,1) };

    Point_2 result[5];

    Point_2 *ptr = CGAL::convex_hull_2( points, points+5, result );

    std::cout << ptr - result << " points on the convex hull" <<

    std::endl;

    return 0;

}

- 在 qt-creator 中,错误: here

.pro 文件: INCLUDEPATH += C:\local\boost_1_59_0\ C:\dev\CGAL-4.9\include\ C:\dev\CGAL-4.9\auxiliary\gmp\include\

LIBS += C:\dev\CGAL-4.9\auxiliary\gmp\lib\libgmp-10.lib\ C:\local\boost_1_59_0\lib64-msvc-12.0\libboost_thread-vc100-mt-gd-1_51.lib\ C:\local\boost_1_59_0\lib64-msvc-12.0\boost_thread-vc120-mt-1_59.lib\ C:\dev\CGAL-4.9\build\lib\CGAL-vc120-mt-gd-4.9.lib\

- 在 Visual Studio 中,错误:

1>------ Build started: Project: cgal_test, Configuration: Debug Win32 ------
1>Source.obj : error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::system_category(void)" (?system_category@system@boost@@YAABVerror_category@12@XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'native_ecat''(void)" (??__Enative_ecat@system@boost@@YAXXZ)
1>Source.obj : error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (?generic_category@system@boost@@YAABVerror_category@12@XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'errno_ecat''(void)" (??__Eerrno_ecat@system@boost@@YAXXZ)
1>Source.obj : error LNK2019: unresolved external symbol "void __cdecl boost::detail::set_tss_data(void const *,class boost::shared_ptr<struct boost::detail::tss_cleanup_function>,void *,bool)" (?set_tss_data@detail@boost@@YAXPBXV?$shared_ptr@Utss_cleanup_function@detail@boost@@@2@PAX_N@Z) referenced in function "public: __thiscall boost::thread_specific_ptr<class CGAL::Lazy<class CGAL::Interval_nt<0>,class CGAL::Gmpq,class CGAL::Lazy_exact_nt<class CGAL::Gmpq>,struct CGAL::To_interval<class CGAL::Gmpq> > >::~thread_specific_ptr<class CGAL::Lazy<class CGAL::Interval_nt<0>,class CGAL::Gmpq,class CGAL::Lazy_exact_nt<class CGAL::Gmpq>,struct CGAL::To_interval<class CGAL::Gmpq> > >(void)" (??1?$thread_specific_ptr@V?$Lazy@V?$Interval_nt@$0A@@CGAL@@VGmpq@2@V?$Lazy_exact_nt@VGmpq@CGAL@@@2@U?$To_interval@VGmpq@CGAL@@@2@@CGAL@@@boost@@QAE@XZ)
1>Source.obj : error LNK2019: unresolved external symbol "void * __cdecl boost::detail::get_tss_data(void const *)" (?get_tss_data@detail@boost@@YAPAXPBX@Z) referenced in function "public: class CGAL::Lazy<class CGAL::Interval_nt<0>,class CGAL::Gmpq,class CGAL::Lazy_exact_nt<class CGAL::Gmpq>,struct CGAL::To_interval<class CGAL::Gmpq> > * __thiscall boost::thread_specific_ptr<class CGAL::Lazy<class CGAL::Interval_nt<0>,class CGAL::Gmpq,class CGAL::Lazy_exact_nt<class CGAL::Gmpq>,struct CGAL::To_interval<class CGAL::Gmpq> > >::get(void)const " (?get@?$thread_specific_ptr@V?$Lazy@V?$Interval_nt@$0A@@CGAL@@VGmpq@2@V?$Lazy_exact_nt@VGmpq@CGAL@@@2@U?$To_interval@VGmpq@CGAL@@@2@@CGAL@@@boost@@QBEPAV?$Lazy@V?$Interval_nt@$0A@@CGAL@@VGmpq@2@V?$Lazy_exact_nt@VGmpq@CGAL@@@2@U?$To_interval@VGmpq@CGAL@@@2@@CGAL@@XZ)
1>Source.obj : error LNK2019: unresolved external symbol __imp____gmpz_add_ui referenced in function "public: class CGAL::Gmpz & __thiscall CGAL::Gmpz::operator+=(int)" (??YGmpz@CGAL@@QAEAAV01@H@Z)
1>Source.obj : error LNK2019: unresolved external symbol __imp____gmpz_clear referenced in function "public: __thiscall CGAL::Gmpz_rep::~Gmpz_rep(void)" (??1Gmpz_rep@CGAL@@QAE@XZ)
1>Source.obj : error LNK2019: unresolved external symbol __imp____gmpz_init referenced in function "public: __thiscall CGAL::Gmpz::Gmpz(void)" (??0Gmpz@CGAL@@QAE@XZ)
1>Source.obj : error LNK2019: unresolved external symbol __imp____gmpz_init_set_si referenced in function "public: __thiscall CGAL::Gmpz::Gmpz(int)" (??0Gmpz@CGAL@@QAE@H@Z)
1>Source.obj : error LNK2019: unresolved external symbol __imp____gmpz_mul_si referenced in function "public: class CGAL::Gmpz & __thiscall CGAL::Gmpz::operator*=(int)" (??XGmpz@CGAL@@QAEAAV01@H@Z)
1>Source.obj : error LNK2019: unresolved external symbol __imp____gmpz_set referenced in function "public: __thiscall CGAL::Gmpq::Gmpq(class CGAL::Gmpz const &,class CGAL::Gmpz const &)" (??0Gmpq@CGAL@@QAE@ABVGmpz@1@0@Z)
1>Source.obj : error LNK2019: unresolved external symbol __imp____gmpz_sub_ui referenced in function "public: class CGAL::Gmpz & __thiscall CGAL::Gmpz::operator+=(int)" (??YGmpz@CGAL@@QAEAAV01@H@Z)
1>Source.obj : error LNK2019: unresolved external symbol __imp____gmpq_add referenced in function "class CGAL::Gmpq __cdecl CGAL::operator+(class CGAL::Gmpq const &,class CGAL::Gmpq const &)" (??HCGAL@@YA?AVGmpq@0@ABV10@0@Z)
1>Source.obj : error LNK2019: unresolved external symbol __imp____gmpq_canonicalize referenced in function "public: __thiscall CGAL::Gmpq::Gmpq(class CGAL::Gmpz const &,class CGAL::Gmpz const &)" (??0Gmpq@CGAL@@QAE@ABVGmpz@1@0@Z)
1>Source.obj : error LNK2019: unresolved external symbol __imp____gmpq_clear referenced in function "public: __thiscall CGAL::Gmpq_rep::~Gmpq_rep(void)" (??1Gmpq_rep@CGAL@@QAE@XZ)
1>Source.obj : error LNK2019: unresolved external symbol __imp____gmpq_cmp referenced in function "public: bool __thiscall CGAL::Gmpq::operator<(class CGAL::Gmpq const &)const " (??MGmpq@CGAL@@QBE_NABV01@@Z)
1>Source.obj : error LNK2019: unresolved external symbol __imp____gmpq_equal referenced in function "public: bool __thiscall CGAL::Gmpq::operator==(class CGAL::Gmpq const &)const " (??8Gmpq@CGAL@@QBE_NABV01@@Z)
1>Source.obj : error LNK2019: unresolved external symbol __imp____gmpq_init referenced in function "public: __thiscall CGAL::Gmpq_rep::Gmpq_rep(void)" (??0Gmpq_rep@CGAL@@QAE@XZ)
1>Source.obj : error LNK2019: unresolved external symbol __imp____gmpq_mul referenced in function "class CGAL::Gmpq __cdecl CGAL::operator*(class CGAL::Gmpq const &,class CGAL::Gmpq const &)" (??DCGAL@@YA?AVGmpq@0@ABV10@0@Z)
1>Source.obj : error LNK2019: unresolved external symbol __imp____gmpq_set_si referenced in function "public: __thiscall CGAL::Gmpq::Gmpq(int)" (??0Gmpq@CGAL@@QAE@H@Z)
1>Source.obj : error LNK2019: unresolved external symbol __imp____gmpq_sub referenced in function "class CGAL::Gmpq __cdecl CGAL::operator-(class CGAL::Gmpq const &,class CGAL::Gmpq const &)" (??GCGAL@@YA?AVGmpq@0@ABV10@0@Z)
1>Source.obj : error LNK2019: unresolved external symbol __imp__mpfr_init2 referenced in function "public: struct std::pair<double,double> __thiscall CGAL::Real_embeddable_traits<class CGAL::Gmpq>::To_interval::operator()(class CGAL::Gmpq const &)const " (??RTo_interval@?$Real_embeddable_traits@VGmpq@CGAL@@@CGAL@@QBE?AU?$pair@NN@std@@ABVGmpq@2@@Z)
1>Source.obj : error LNK2019: unresolved external symbol __imp__mpfr_clear referenced in function "public: struct std::pair<double,double> __thiscall CGAL::Real_embeddable_traits<class CGAL::Gmpq>::To_interval::operator()(class CGAL::Gmpq const &)const " (??RTo_interval@?$Real_embeddable_traits@VGmpq@CGAL@@@CGAL@@QBE?AU?$pair@NN@std@@ABVGmpq@2@@Z)
1>Source.obj : error LNK2019: unresolved external symbol __imp__mpfr_set_q referenced in function "public: struct std::pair<double,double> __thiscall CGAL::Real_embeddable_traits<class CGAL::Gmpq>::To_interval::operator()(class CGAL::Gmpq const &)const " (??RTo_interval@?$Real_embeddable_traits@VGmpq@CGAL@@@CGAL@@QBE?AU?$pair@NN@std@@ABVGmpq@2@@Z)
1>Source.obj : error LNK2019: unresolved external symbol __imp__mpfr_get_d referenced in function "public: struct std::pair<double,double> __thiscall CGAL::Real_embeddable_traits<class CGAL::Gmpq>::To_interval::operator()(class CGAL::Gmpq const &)const " (??RTo_interval@?$Real_embeddable_traits@VGmpq@CGAL@@@CGAL@@QBE?AU?$pair@NN@std@@ABVGmpq@2@@Z)
1>E:\os\cgal_test\Debug\cgal_test.exe : fatal error LNK1120: 24 unresolved externals

项目配置here

感谢您的帮助,谢谢

【问题讨论】:

    标签: c++ boost qt-creator cgal


    【解决方案1】:

    您需要为链接器提供 boost 库。在 Visual Studio 的链接器属性中,将正确的目录添加到“附加库目录”中。

    Unresolved external 表示您有某个函数或变量的声明,但链接器找不到定义。这通常发生在使用 3rd 方库时,这些库为您提供作为头文件的接口,而不是编译为库文件的实际代码。

    【讨论】:

    • 我已经在链接器属性中添加了以下路径:C:\local\boost_1_59_0\libs; C:\local\boost_1_59_0\lib64-msvc-12.0;C:\local\boost_1_59_0;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-31
    • 1970-01-01
    • 2021-06-14
    • 1970-01-01
    • 2017-02-17
    • 2019-09-11
    • 2021-11-19
    相关资源
    最近更新 更多