我编写了一个 c++ 程序并尝试使用 curlpp 通过SSL
. 问题是,我无法链接该程序。
操作系统:Ubuntu 15.10
错误:
/usr/bin/cmake -E cmake_link_script CMakeFiles/prtg_probe.dir/link.txt --verbose=1 Wird gelinkt prtg_probe (c++) CMakeFiles/prtg_probe.dir/probe.cpp.o: 在函数 curlpp::internal::OptionContainer , std::allocator >, std::allocator, std::allocator > > >
::OptionContainer(std::__cxx11::list, std::allocator >, std::allocator, std::allocator > > > const&)': /usr/include/curlpp/internal/OptionContainer.inl:38: 未定义引用 curlpp::internal::SList::SList(std::__cxx11::list, std::allocator >, std::allocator, std::allocator > > > const&)' CMakeFiles/prtg_probe.dir/probe。 cpp.o: 在函数 curlpp::internal::OptionContainer, std::allocator >, std::allocator, std::allocator > > ::setValue(std::__cxx11::list, std::allocator >, std::allocator, std::allocator > > > const&)': /usr/include/curlpp/internal/OptionContainer.inl:52: 未定义引用`curlpp::internal::SList::operator=(std:: __cxx11::list, std::allocator >, std::allocator, std::allocator > > >const&)' ....
这是产生错误的代码:
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <cctype>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <cerrno>
#include <boost/bind.hpp>
#include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
#include <curlpp/Exception.hpp>
....
class myclass
{
....
try
{
curlpp::Cleanup cleaner;
curlpp::Easy request;
ostringstream os;
request.setOpt(new curlpp::options::Url(&url_announce[0]));
request.setOpt(new curlpp::options::SslEngineDefault());
list<string> header;
header.push_back("Content-Type: text/*");
request.setOpt(new curlpp::options::HttpHeader(header));
request.setOpt(new curlpp::options::PostFields(data_announce));
request.setOpt(new curlpp::options::PostFieldSize((long)data_announce.length()));
request.setOpt(new curlpp::options::WriteStream(&os));
request.perform();
request_announce = os.str();
}
catch (curlpp::LogicError & e)
{
syslog(LOG_DAEMON, "Error accessing PRTG server: %s", e.what());
}
catch (curlpp::RuntimeError & e)
{
syslog(LOG_DAEMON, "Error accessing PRTG server: %s", e.what());
}
每一行在curlpp::options::...
链接时都会产生一个错误。我已经环顾四周并搜索了几个小时,但我发现的只是将 libcurl 与 libcurl 链接在一起。我这样做了,但仍然得到这个错误。
这是完整的链接行:
/usr/bin/c++ -g CMakeFiles/prtg_probe.dir/sensors.cpp.o
CMakeFiles/prtg_probe.dir/mini_probe.cpp.o CMakeFiles/prtg_probe.dir/probe.cpp.o
CMakeFiles/prtg_probe.dir/helper.cpp.o
CMakeFiles/prtg_probe.dir/config.cpp.o CMakeFiles/prtg_probe.dir/main.cpp.o
-o prtg_probe -rdynamic -lm -lpthread -lcrypto -lssl -lcurlpp -lcurl -lboost_system -lboost_filesystem -ljsoncpp -luuid
有人知道我错过了什么吗?我是否必须再添加一个库,如果是,是哪一个?
我尝试使用以下命令编译example00.cpp :
g++ -o example00 example00.cpp -lm -lcurl -lcurlpp
结果:
/tmp/cc3pcvDc.o: In Funktion `curlpp::OptionTrait<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, (CURLoption)10002>::updateHandleToMe(curlpp::internal::CurlHandle*) const':
example00.cpp: (.text._ZNK6curlpp11OptionTraitINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEL10CURLoption10002EE16updateHandleToMeEPNS_8internal10CurlHandleE[_ZNK6curlpp11OptionTraitINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEL10CURLoption10002EE16updateHandleToMeEPNS_8internal10CurlHandleE]+0x68):
Nicht definierter Verweis auf `curlpp::UnsetOption::UnsetOption(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/cc3pcvDc.o: In Funktion `curlpp::Option<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::getValue() const':
example00.cpp: (.text._ZNK6curlpp6OptionINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE8getValueEv[_ZNK6curlpp6OptionINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE8getValueEv]+0x68):
Nicht definierter Verweis auf `curlpp::UnsetOption::UnsetOption(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
这对我来说似乎是同样的问题。