curlpp
curlpp copied to clipboard
The following error occurs on linux gnu (Ubuntu 18.04) distro. Am I missing a package? Which undefined resolution is left out?
/tmp/ccIk0bXG.o: In function `curlpp::OptionTrait<std::function<unsigned long (char*, unsigned long, unsigned long)>, (CURLoption)20011>::updateHandleToMe(curlpp::internal::CurlHandle*) const':
code.cpp:(.text._ZNK6curlpp11OptionTraitISt8functionIFmPcmmEEL10CURLoption20011EE16updateHandleToMeEPNS_8internal10CurlHandleE[_ZNK6curlpp11OptionTraitISt8functionIFmPcmmEEL10CURLoption20011EE16updateHandleToMeEPNS_8internal10CurlHandleE]+0x6a): undefined reference to `curlpp::internal::OptionSetter<std::function<unsigned long (char*, unsigned long, unsigned long)>, (CURLoption)20011>::setOpt(curlpp::internal::CurlHandle*, std::function<unsigned long (char*, unsigned long, unsigned long)>&)'
/tmp/ccIk0bXG.o: In function `curlpp::OptionTrait<std::function<int (double, double, double, double)>, (CURLoption)20056>::updateHandleToMe(curlpp::internal::CurlHandle*) const':
code.cpp:(.text._ZNK6curlpp11OptionTraitISt8functionIFiddddEEL10CURLoption20056EE16updateHandleToMeEPNS_8internal10CurlHandleE[_ZNK6curlpp11OptionTraitISt8functionIFiddddEEL10CURLoption20056EE16updateHandleToMeEPNS_8internal10CurlHandleE]+0x6a): undefined reference to `curlpp::internal::OptionSetter<std::function<int (double, double, double, double)>, (CURLoption)20056>::setOpt(curlpp::internal::CurlHandle*, std::function<int (double, double, double, double)>&)'
collect2: error: ld returned 1 exit status
The following C++ code gives the error.
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
#include <curlpp/cURLpp.hpp>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <mutex>
using std::operator""s;
namespace
{
unsigned ln = 1;
auto Color(int n, const std::string& s) { return "\33[38;5;"+std::to_string(n)+'m'+s+"\33[m"; }
auto Line(int l) { int m=l-ln; ln=l; return "\r"+(m<0?"\33["+std::to_string(-m)+'A':std::string(m,'\n')); }
std::mutex print_lock;
std::size_t Download(const std::string& url, const std::string& filename, unsigned line)
{
std::ofstream of(filename);
std::size_t written = 0;
cURLpp::Easy req;
req.setOpt(cURLpp::Options::Url(url));
req.setOpt(cURLpp::Options::NoProgress(false));
req.setOpt(cURLpp::Options::FollowLocation(true));
req.setOpt(cURLpp::Options::ProgressFunction([&](std::size_t total, std::size_t done, auto...)
{
std::lock_guard<std::mutex> l(print_lock);
std::cout << Line(line) << Color(143, filename + ": ") << done << " of " << total
<< " bytes received (" << int(total ? done*100./total : 0) << "%)" << std::flush;
return 0;
}));
req.setOpt(cURLpp::Options::WriteFunction([&](const char* p, std::size_t size, std::size_t nmemb)
{
of.write(p, size*nmemb);
written += size*nmemb;
return size*nmemb;
}));
req.perform();
return written;
}
auto root = "http://iki.fi/bisqwit/ctu85/"s; // http://www.unicode.org/Public/MAPPINGS/ISO8859/
}
#include <future>
int main()
{
cURLpp::initialize();
unsigned line=1;
std::vector<std::future<std::size_t>> sizes;
for(const auto& p: {"8859-1.TXT"s, "8859-2.TXT"s, "8859-3.TXT"s, "8859-4.TXT"s, "8859-5.TXT"s,
"8859-6.TXT"s, "8859-7.TXT"s, "8859-8.TXT"s, "8859-9.TXT"s, "8859-10.TXT"s,
"8859-11.TXT"s,"8859-13.TXT"s,"8859-14.TXT"s,"8859-15.TXT"s,"8859-16.TXT"s})
{
sizes.emplace_back(std::async(std::launch::async, [p, l=line++]
{
return Download(root+p, p, l);
}));
}
std::size_t total = 0;
for(auto& s: sizes) total += s.get();
std::cout << Line(line) << Color(174, std::to_string(total) + " bytes downloaded total\n");
}

Same problem here when I run:
#include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
#include <iostream>
int main() {
try {
curlpp::Cleanup cleanup;
{
std::cout << curlpp::options::Url("http://google.com");
}
} catch (curlpp::RuntimeError& e) {
std::cout << e.what() << std::endl;
} catch (curlpp::LogicError& e) {
std::cout << e.what() << std::endl;
}
}
Here is the error message:
CMakeFiles/ssr_server_connect_node.dir/src/main_node.cpp.o: In function `main':
main_node.cpp:(.text+0x67): undefined reference to `operator<<(std::ostream&, curlpp::OptionTrait<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, (CURLoption)10002> const&)'
CMakeFiles/ssr_server_connect_node.dir/src/main_node.cpp.o: In function `curlpp::OptionTrait<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, (CURLoption)10002>::updateHandleToMe(curlpp::internal::CurlHandle*) const':
main_node.cpp:(.text._ZNK6curlpp11OptionTraitINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEL10CURLoption10002EE16updateHandleToMeEPNS_8internal10CurlHandleE[_ZNK6curlpp11OptionTraitINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEL10CURLoption10002EE16updateHandleToMeEPNS_8internal10CurlHandleE]+0x68): undefined reference to `curlpp::UnsetOption::UnsetOption(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
CMakeFiles/ssr_server_connect_node.dir/src/main_node.cpp.o: In function `curlpp::Option<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::getValue() const':
main_node.cpp:(.text._ZNK6curlpp6OptionINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE8getValueEv[_ZNK6curlpp6OptionINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE8getValueEv]+0x68): undefined reference to `curlpp::UnsetOption::UnsetOption(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
I had to do a hell lot of things to get the problem fixed. The order of linking matters. I copied the binary files in to a /usr/bin dir and includes into /usr/include. This is not one by default.
Please work on the issue guys. It is a painstaking job to do it every time there is an issue with curlpp.