Boost单元测试链接错误-abi不匹配? [英] Boost unit test link error -- abi mismatch?

查看:375
本文介绍了Boost单元测试链接错误-abi不匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用boost构建单元测试,但是链接器抱怨缺少功能.拿这个骨架代码

#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(TestFuncOps);

BOOST_AUTO_TEST_CASE(CopyConstructor)
{
}    

BOOST_AUTO_TEST_SUITE_END();

但是失败了

Undefined symbols for architecture x86_64:
  "boost::unit_test::ut_detail::normalize_test_case_name[abi:cxx11](boost::unit_test::basic_cstring<char const>)", referenced from:
      __GLOBAL__sub_I_funcopstest.cc in funcopstest.o

libboost_unit_test_framework是通过我的链接器命令找到的:

g++-5 --std=c++14 funcopstest.o -L/usr/local/lib -lboost_unit_test_framework -o test_funcops

因为拿走-lboost_unit_test_framework时,我得到了大量的未定义引用,而不仅仅是一个. Boost是使用c ++ 11模式通过brew从源安装的.我尝试使用每个-fabi-version=[0-8]进行编译,但没有任何改变.

有人知道发生了什么事吗?

解决方案

CPPFLAGS中添加-D_GLIBCXX_USE_CXX11_ABI=0,然后重新编译.

gcc 5随附的libstdc ++必须对std::stringstd::list进行一些更改以符合C ++ 11.为了向后兼容,它支持双ABI ,但默认情况下使用新的ABI.

您的libboost_unit_test_framework.so似乎在不支持新代码的情况下(可能在gcc 4.x中)被编译,因此在编译代码时,编译器将生成预期与支持新代码的库链接的代码.如果两个ABI不同,则将丢失符号.将_GLIBCXX_USE_CXX11_ABI宏定义为0会使gcc 5使用旧的库代码.

或者,您可以使用gcc 5重建Boost.Test.

I'm trying to build a unit test with boost, but the linker complains about a missing function. Take this skeleton code

#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(TestFuncOps);

BOOST_AUTO_TEST_CASE(CopyConstructor)
{
}    

BOOST_AUTO_TEST_SUITE_END();

But it fails with

Undefined symbols for architecture x86_64:
  "boost::unit_test::ut_detail::normalize_test_case_name[abi:cxx11](boost::unit_test::basic_cstring<char const>)", referenced from:
      __GLOBAL__sub_I_funcopstest.cc in funcopstest.o

The libboost_unit_test_framework is found by my linker command:

g++-5 --std=c++14 funcopstest.o -L/usr/local/lib -lboost_unit_test_framework -o test_funcops

because when take away the -lboost_unit_test_framework, I get a ton of undefined references instead of only one. Boost was installed via brew from source using c++11 mode. I have tried to compile with every -fabi-version=[0-8] but nothing changed.

Does anybody have a clue what's going on?

解决方案

Add -D_GLIBCXX_USE_CXX11_ABI=0 to your CPPFLAGS, then recompile.

The libstdc++ that comes with gcc 5 had to make some changes to std::string and std::list for conformance with C++11. For backwards compatibility it supports a dual ABI, but it uses the new ABI by default.

Your libboost_unit_test_framework.so appears to be compiled without support for the new one (possibly with gcc 4.x), so when you compile your code, the compiler will generate code that expects to be linked against libraries supporting the new one. In cases where the two ABIs differ, symbols will be missing. Defining the _GLIBCXX_USE_CXX11_ABI macro to 0 makes gcc 5 use the old library code.

Alternatively, you could rebuild Boost.Test with gcc 5.

这篇关于Boost单元测试链接错误-abi不匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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