This question already has an answer here:
I am trying to use CPR library to make GET and POST request from C++.
I have build the library this way
cd /path/to/project/dir git submodule add git@github.com:whoshuu/cpr.git git submodule update --init --recursive cd cpr && mkdir build && cd build && cmake .. make sudo make install
And it build successfully. When i am trying to compile my project, i received the error about undefined reference, which mean the library linkage fails.
I have tried compiling my project with -I cpr/build/lib, -L cpr/lib, and -L cpr/buil/lib the following error have been received.
main.cpp:(.text+0x876b): undefined reference to `cpr::Parameters::Parameters(std::initializer_list<cpr::Parameter> const&)'
/tmp/cctmmgHh.o: In function `cpr::Response cpr::Get<std::string, cpr::Authentication, cpr::Parameters>(std::string&&, cpr::Authentication&&, cpr::Parameters&&)':
main.cpp:(.text._ZN3cpr3GetIISsNS_14AuthenticationENS_10ParametersEEEENS_8ResponseEDpOT_[_ZN3cpr3GetIISsNS_14AuthenticationENS_10ParametersEEEENS_8ResponseEDpOT_]+0x23): undefined reference to `cpr::Session::Session()'
main.cpp:(.text._ZN3cpr3GetIISsNS_14AuthenticationENS_10ParametersEEEENS_8ResponseEDpOT_[_ZN3cpr3GetIISsNS_14AuthenticationENS_10ParametersEEEENS_8ResponseEDpOT_]+0x75): undefined reference to `cpr::Session::Get()'
main.cpp:(.text._ZN3cpr3GetIISsNS_14AuthenticationENS_10ParametersEEEENS_8ResponseEDpOT_[_ZN3cpr3GetIISsNS_14AuthenticationENS_10ParametersEEEENS_8ResponseEDpOT_]+0x82): undefined reference to `cpr::Session::~Session()'
main.cpp:(.text._ZN3cpr3GetIISsNS_14AuthenticationENS_10ParametersEEEENS_8ResponseEDpOT_[_ZN3cpr3GetIISsNS_14AuthenticationENS_10ParametersEEEENS_8ResponseEDpOT_]+0x93): undefined reference to `cpr::Session::~Session()'
/tmp/cctmmgHh.o: In function `std::map<std::string, std::string, cpr::CaseInsensitiveCompare, std::allocator<std::pair<std::string const, std::string> > >::operator[](std::string&&)':
main.cpp:(.text._ZNSt3mapISsSsN3cpr22CaseInsensitiveCompareESaISt4pairIKSsSsEEEixEOSs[_ZNSt3mapISsSsN3cpr22CaseInsensitiveCompareESaISt4pairIKSsSsEEEixEOSs]+0x90): undefined reference to `cpr::CaseInsensitiveCompare::operator()(std::string const&, std::string const&) const'
/tmp/cctmmgHh.o: In function `void cpr::priv::set_option<std::string>(cpr::Session&, std::string&&)':
main.cpp:(.text._ZN3cpr4priv10set_optionISsEEvRNS_7SessionEOT_[_ZN3cpr4priv10set_optionISsEEvRNS_7SessionEOT_]+0x2a): undefined reference to `cpr::Session::SetOption(std::string const&)'
/tmp/cctmmgHh.o: In function `std::_Rb_tree<std::string, std::pair<std::string const, std::string>, std::_Select1st<std::pair<std::string const, std::string> >, cpr::CaseInsensitiveCompare, std::allocator<std::pair<std::string const, std::string> > >::_M_get_insert_hint_unique_pos(std::_Rb_tree_const_iterator<std::pair<std::string const, std::string> >, std::string const&)':
main.cpp:(.text._ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_EN3cpr22CaseInsensitiveCompareESaIS2_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS2_ERS1_[_ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_EN3cpr22CaseInsensitiveCompareESaIS2_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS2_ERS1_]+0xa1): undefined reference to `cpr::CaseInsensitiveCompare::operator()(std::string const&, std::string const&) const'
main.cpp:(.text._ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_EN3cpr22CaseInsensitiveCompareESaIS2_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS2_ERS1_[_ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_EN3cpr22CaseInsensitiveCompareESaIS2_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS2_ERS1_]+0x147): undefined reference to `cpr::CaseInsensitiveCompare::operator()(std::string const&, std::string const&) const'
main.cpp:(.text._ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_EN3cpr22CaseInsensitiveCompareESaIS2_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS2_ERS1_[_ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_EN3cpr22CaseInsensitiveCompareESaIS2_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS2_ERS1_]+0x202): undefined reference to `cpr::CaseInsensitiveCompare::operator()(std::string const&, std::string const&) const'
main.cpp:(.text._ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_EN3cpr22CaseInsensitiveCompareESaIS2_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS2_ERS1_[_ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_EN3cpr22CaseInsensitiveCompareESaIS2_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS2_ERS1_]+0x2dd): undefined reference to `cpr::CaseInsensitiveCompare::operator()(std::string const&, std::string const&) const'
main.cpp:(.text._ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_EN3cpr22CaseInsensitiveCompareESaIS2_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS2_ERS1_[_ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_EN3cpr22CaseInsensitiveCompareESaIS2_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS2_ERS1_]+0x386): undefined reference to `cpr::CaseInsensitiveCompare::operator()(std::string const&, std::string const&) const'
/tmp/cctmmgHh.o:main.cpp:(.text._ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_EN3cpr22CaseInsensitiveCompareESaIS2_EE14_M_insert_nodeEPSt18_Rb_tree_node_baseSA_PSt13_Rb_tree_nodeIS2_E[_ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_EN3cpr22CaseInsensitiveCompareESaIS2_EE14_M_insert_nodeEPSt18_Rb_tree_node_baseSA_PSt13_Rb_tree_nodeIS2_E]+0x5e): more undefined references to `cpr::CaseInsensitiveCompare::operator()(std::string const&, std::string const&) const' follow
/tmp/cctmmgHh.o: In function `void cpr::priv::set_option<cpr::Authentication>(cpr::Session&, cpr::Authentication&&)':
main.cpp:(.text._ZN3cpr4priv10set_optionINS_14AuthenticationEEEvRNS_7SessionEOT_[_ZN3cpr4priv10set_optionINS_14AuthenticationEEEvRNS_7SessionEOT_]+0x2a): undefined reference to `cpr::Session::SetOption(cpr::Authentication const&)'
/tmp/cctmmgHh.o: In function `void cpr::priv::set_option<cpr::Parameters>(cpr::Session&, cpr::Parameters&&)':
main.cpp:(.text._ZN3cpr4priv10set_optionINS_10ParametersEEEvRNS_7SessionEOT_[_ZN3cpr4priv10set_optionINS_10ParametersEEEvRNS_7SessionEOT_]+0x2a): undefined reference to `cpr::Session::SetOption(cpr::Parameters&&)'
/tmp/cctmmgHh.o: In function `std::_Rb_tree<std::string, std::pair<std::string const, std::string>, std::_Select1st<std::pair<std::string const, std::string> >, cpr::CaseInsensitiveCompare, std::allocator<std::pair<std::string const, std::string> > >::_M_lower_bound(std::_Rb_tree_node<std::pair<std::string const, std::string> >*, std::_Rb_tree_node<std::pair<std::string const, std::string> >*, std::string const&)':
main.cpp:(.text._ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_EN3cpr22CaseInsensitiveCompareESaIS2_EE14_M_lower_boundEPSt13_Rb_tree_nodeIS2_ESB_RS1_[_ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_EN3cpr22CaseInsensitiveCompareESaIS2_EE14_M_lower_boundEPSt13_Rb_tree_nodeIS2_ESB_RS1_]+0x38): undefined reference to `cpr::CaseInsensitiveCompare::operator()(std::string const&, std::string const&) const'
/tmp/cctmmgHh.o: In function `std::_Rb_tree<std::string, std::pair<std::string const, std::string>, std::_Select1st<std::pair<std::string const, std::string> >, cpr::CaseInsensitiveCompare, std::allocator<std::pair<std::string const, std::string> > >::_M_get_insert_unique_pos(std::string const&)':
main.cpp:(.text._ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_EN3cpr22CaseInsensitiveCompareESaIS2_EE24_M_get_insert_unique_posERS1_[_ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_EN3cpr22CaseInsensitiveCompareESaIS2_EE24_M_get_insert_unique_posERS1_]+0x5c): undefined reference to `cpr::CaseInsensitiveCompare::operator()(std::string const&, std::string const&) const'
main.cpp:(.text._ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_EN3cpr22CaseInsensitiveCompareESaIS2_EE24_M_get_insert_unique_posERS1_[_ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_EN3cpr22CaseInsensitiveCompareESaIS2_EE24_M_get_insert_unique_posERS1_]+0x11b): undefined reference to `cpr::CaseInsensitiveCompare::operator()(std::string const&, std::string const&) const'
collect2: error: ld returned 1 exit status
When i am compiling using -lcpr it says
/usr/bin/ld: cannot find -lcpr collect2: error: ld returned 1 exit status
Aucun commentaire:
Enregistrer un commentaire