链接器错误的函数期望const std :: string& [英] Linker error for functions expecting const std::string &

查看:692
本文介绍了链接器错误的函数期望const std :: string&的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当试图链接到共享库( gtkmm )时,对于其签名包含 std :: string const&

When trying to link against a shared library (gtkmm), I get linker errors for functions whose signature contains a std::string const&.

例如,如果函数声明为

void set_icon_from_file(const std::string&);

g ++报告

undefined reference to `Gtk::Window::set_icon_from_file(std::string const&)'


$ b b

我使用 pkg-config 中的链接器标志,这不会发生在其他函数(例如,以原始类型为参数的函数)可能链接器配置正确。

I am using the linker flags from pkg-config, and this does not happen for other functions (functions taking primitive types as arguments, for example), so I suspect the linker is configured properly.

readelf

45: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND _ZN3Gtk6Window18set_icon_from_fileERKSs


$ b b

和共享库

and on the shared library

10991: 00000000003c0950    96 FUNC    GLOBAL DEFAULT   11 _ZN3Gtk6Window18set_icon_from_fileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE

我不知道该怎么做。我检查了在库头和源中使用相同的签名来声明函数。因为 __ cxx11 部分在错误名称中,我首先怀疑C ++版本之间的兼容性问题,但是,我正在使用C ++ 11构建。

I'm not sure what to make of that. I checked that the functions are declared with the same signature in both the library headers and source. Because of the __cxx11 part in the mangled name, I first suspected a compatibility issue between C++ versions, however, I'm building with C++11 as well.

推荐答案

查看我的c ++ - filt输出:

Look at my c++-filt output:

_ZN3Gtk6Window18set_icon_from_fileERKSs
Gtk::Window::set_icon_from_file(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
_ZN3Gtk6Window18set_icon_from_fileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Gtk::Window::set_icon_from_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)

这意味着第二个版本是在启用glibcxx11 abi的情况下编译的。
这里更多相关资讯。

It means that the second version is compiled with glibcxx11 abi enabled. Here more information about it.

所以,基本上你需要更新你的gcc到5.1版本或降级库。

So, basically you need to update your gcc to 5.1 version or downgrade the library.

这篇关于链接器错误的函数期望const std :: string&amp;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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