【发布时间】:2019-02-22 03:26:03
【问题描述】:
在我的工作场所,我们有一个项目,其中包含许多需要为 ARM 和 x86 构建的应用程序。 ARM 版本使用 Marvell GCC 4.8.5 跨工具链构建良好。现在我正在开发 x86 版本(GCC 版本 4.8.5-4ubuntu8),并在一个应用程序中遇到了几个未定义的参考错误。不幸的是,我既不能分享资源(可能只是其中的一部分),也不能做最小的例子,这会显示错误,但我对这个问题进行了一些调查,这就是我发现的。
应用链接失败阶段显示以下错误:
src/<...>.o:(.data.rel.ro.<...>[<...>]+0xc0): undefined reference to `non-virtual thunk to <...>::OnBeforeRun()'
src/<...>.o:(.data.rel.ro.<...>[<...>]+0xc8): undefined reference to `non-virtual thunk to <...>::OnRun()'
src/<...>.o:(.data.rel.ro.<...>[<...>]+0xd0): undefined reference to `non-virtual thunk to <...>::OnAfterRun()'
src/<...>.o: In function `<...>::Application(<...>::Runtime&, <...>::SystemFacilityCollection&, <...>::Logger&, char const*, int, char const**)':
<...>/dhcconf.cxx:11: undefined reference to `<...>::Name() const'
src/<...>.o: In function `main':
<...>/main.cxx:21: undefined reference to `<...>::Syslog(std::string const&)'
collect2: error: ld returned 1 exit status
不知道如何处理导致“非虚拟重击”错误(这是另一个问题,但现在让我们忽略它们),但关于最后两个错误,我有一些关于导致它们的提示。
我找到了包含无法解析的函数的库(<...>::Name 来自<...>/dhcconf.cxx:11 和<...>::Syslog 来自<...>/main.cxx:21)并列出了其中的符号(当然这个库是用@ 正确指定的987654326@标志):
$ nm --demangle --dynamic --defined-only --extern-only <...>.so | grep Name
0000000000245956 T <...>::Name[abi:cxx11]() const
$ nm --demangle --dynamic --defined-only --extern-only <...>.so | grep Syslog
000000000025e392 T <...>::Syslog(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
此库中还有许多其他符号也包含 [abi:cxx11] 说明符并使用 __cxx11 类型,但似乎目标应用程序不使用它们,我很确定这些与 cxx11 相关的东西会导致错误。
损坏的应用是使用-std=gnu++0x 标志构建的。尝试使用-D_GLIBCXX_USE_CXX11_ABI=0 构建包含所需符号的库,它使目标应用程序构建良好,但破坏了其他应用程序,所以不是这样。我找不到解决此错误的其他方法。
有人可以帮我解决这个问题吗?提前致谢。
【问题讨论】:
标签: c++ linux c++11 gcc linker