使用curlpp链接错误 [英] Link errors with curlpp

查看:1781
本文介绍了使用curlpp链接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个c ++程序,并尝试使用curlpp通过 SSL 安全地访问http服务器。

I wrote a c++ program and try to use curlpp to access a http server securely over SSL. The problem is, that I can't link the program.

操作系统: 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 ::内部:: OptionContainer,性病::分配器>,
std :: allocator,std :: allocator>>>

/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: In function curlpp::internal::OptionContainer, std::allocator >, std::allocator, std::allocator > > >


:: OptionContainer(std :: __ cxx11 :: list,std: :分配器>,
的std ::分配器,性病::分配器>>>常量和放大器;):
/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 ::内部:: OptionContainer,性病::分配器>,
的std ::分配器,性病::分配器>>>
:: 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&)'
....

::OptionContainer(std::__cxx11::list, std::allocator >, std::allocator, std::allocator > > > const&)': /usr/include/curlpp/internal/OptionContainer.inl:38: undefined reference to curlpp::internal::SList::SList(std::__cxx11::list, std::allocator >, std::allocator, std::allocator > > > const&)' CMakeFiles/prtg_probe.dir/probe.cpp.o: In function 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: undefined reference to `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 ::。 .. 在链接时产生一个错误。我已经环顾四周,搜索Google几个小时,但我发现是将libcurl与libcurl链接。

Every line with curlpp::options::... produces one error at link time. I've looked around and searched Google for hours now, but all I found was to link libcurl together with libcurl. I do that, but still get this errors.

这是完整的链接行:

/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

有人知道我错过了什么吗?是否需要添加一个库?如果是,请添加一个库。

Does anybody know what I'm missing? Do I have to add one more library and if yes which one?

我试图编译 example00.cpp 使用以下命令:

I've tried to compile the example00.cpp with the following command:

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

推荐答案

问题是 ccurlcpp :: UnsetOption :: UnsetOption
的链接在 lipcurlcpp.so 二进制。

The problem is that linkage of ccurlcpp::UnsetOption::UnsetOption is partially defective in the lipcurlcpp.so binary.

链接器投诉:

g++ -o example00 example00.cpp -lm -lcurl -lcurlpp

是:

undefined reference to `curlpp::UnsetOption::UnsetOption(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'

但如果我解构构造函数签名 libcurlpp.so

But if I demangle the constructor signatures in libcurlpp.so:

nm -D -C libcurlpp.so | grep UnsetOption::UnsetOption

我看到:

0000000000021776 T curlpp::UnsetOption::UnsetOption(char const*)
000000000002173e T curlpp::UnsetOption::UnsetOption(std::string const&)

std :: string typedefed由于某些原因。如果
我从
curlpp 0.7.3 源包中得到定义了这个构造函数的源文件,异常。 cpp ,编译它:

The std::string hasn't been properly de-typedefed for some reason. If I get the source file in which this constructor is defined from the curlpp 0.7.3 source package, Exception.cpp, compile it:

curlpp-0.7.3/src/curlpp$ g++ -I../../include -I. -c Exception.cpp

,然后从目标文件中解构构造函数签名:

and then demangle the constructor signatures from the object file:

nm -C Exception.o | grep UnsetOption::UnsetOption

我得到:

00000000000003f4 T curlpp::UnsetOption::UnsetOption(char const*)
00000000000003c2 T curlpp::UnsetOption::UnsetOption(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)



<

So:

curlpp::UnsetOption::UnsetOption(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)

是编译器告诉链接器的签名寻找,但那是
不是在图书馆的签名。

is the signature the compiler is telling the linker to look for, but that is not the signature in the library. The short explanation of the error is: the library is broken.

但是,我们发现没有这样的不一致会影响构造函数的其他重载:

However, we see that no such inconsistency affects the other overload of the constructor:

curlpp::UnsetOption::UnsetOption(char const*)

也不能,因为 char const * 是内置类型。

nor could it, since the char const * is a builtin type.

这使得可以进行黑客修复。其中未定义引用调用是
编译的文件是(已安装) /usr/include/curlpp/Option.inl ,在行:

This enables a hack fix. The file in which the undefined-reference call is compiled is (as installed) /usr/include/curlpp/Option.inl, at the line:

throw UnsetOption(std::string("You are trying to set an unset option to a handle"));

以root身份编辑此文件,您会看到它(不一致)包含两个实例

Edit this file, as root, and you see that it (inconsistently) contains two instances of:

throw UnsetOption(std::string("blah blah"));

和一个实例:

throw UnsetOption("blah blah");

更改 UnsetOption(std :: string(blah blah )) UnsetOption(blah blah)
然后只有好的构造函数在这个文件中调用,并且 example00 ,至少,
编译和链接。

Change the occurrences of UnsetOption(std::string("blah blah")) to UnsetOption("blah blah"). Then only the good constructor is called in this file and example00, at least, will compile and link.

如果你不喜欢黑客,或发现问题重新暴露在其他地方,那么你
可以下载ubuntu源包 curlpp_0.7.3.orig.tar.gz
并构建和安装它自己。这是正确的补救办法。

If you dislike the hack, or find that the problem re-surfaces elsewhere, then you may download the ubuntu source package curlpp_0.7.3.orig.tar.gz and build and install it yourself. That is the right remedy.

这篇关于使用curlpp链接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆