将Boost链接到c ++项目

时间:2018-03-11 10:29:34

标签: c++ boost qt-creator cgal

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

虽然使用qt creator或visual studio包含了对c ++项目的提升,但它显示了很多错误

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 \包括\                 C:\ dev的\ CGAL-4.9 \辅助\ GMP \包括\

LIBS + = C:\ dev \ CGAL-4.9 \ auxiliary \ gmp \ lib \ libgmp-10.lib \         C:\本地\ boost_1_59_0 \ lib64的-MSVC 12.0 \ libboost_thread-VC100-MT-GD-1_51.lib \         C:\本地\ boost_1_59_0 \ lib64的-MSVC 12.0 \ boost_thread-VC120-MT-1_59.lib \         C:\ dev的\ CGAL-4.9 \构建\ 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

我感谢任何帮助,谢谢

1 个答案:

答案 0 :(得分:0)

您需要为链接器提供boost库。在visual studio中的链接器属性中,将正确的目录添加到&#34;其他库目录&#34;。

未解析的外部意味着您具有某个函数或变量的声明,但链接器无法找到该定义。这通常发生在使用第三方库时,它们将接口作为头文件提供,而不是将实际代码编译为库文件。