简体   繁体   中英

linking Boost to c++ project

I have a problem while using BOOST libraries , I downloaded boost_1_59_0 installer and install it to "C:\\local\\boost_1_59_0" then I added the boost variables as following click here

while including boost in c++ project using qt creator or visual studio , it shows a lot of errors

CGAL example:

#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;

}

- in qt-creator , the errors: here

.pro file : 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\\

- in visual studio , the errors:

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

project configuration : here

I appreciate any help , thanks

You need to provide the linker with the boost libraries. In the linker properties in visual studio, add the correct directory to "Additional Library Directories".

Unresolved external means that you have a declaration of some function or variable, but the linker cannot find the definition. This usually happens when using 3rd party libraries which provide you with the interface as header files, but not with the actual code which is compiled as library files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM