gcc使用c ++ 11标准,即使明确指定了98 [英] gcc using c++11 standard even though 98 explicitly specified

查看:123
本文介绍了gcc使用c ++ 11标准,即使明确指定了98的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一个奇怪的错误,怀疑与我的系统配置有关。我正在使用g ++ --version = g ++(Ubuntu 5.4.0-6ubuntu1〜16.04.4)5.4.0 20160609 编译/链接普通的c ++程序。 默认语言标准记录为c ++ 98,但是即使指定了-std = c ++ 98选项,我仍在输出.o文件中看到c ++ 11符号。。这是我的test.cpp:

I'm getting a strange error I suspect has to do with my system configuration. I am compiling/linking a trivial c++ program using g++ --version = g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609. The default language standard is documented to be c++98, yet even with the -std=c++98 option specified, I am seeing c++11 symbols in the output .o file. This is my test.cpp:

#include <string>
int main() {
  std::string str = "Hello World!";
  return 0;
}

这是我的编译和链接命令(可能带有不必要的显式语言标准选项)以及相关的输出:

Here are my compile and link commands (with presumably unnecessary explicit language standard option) and associated output:

$ g++ -c -Wall -std=c++98 -o test.o test.cpp
$ g++ -Wall -std=c++98 -o test test.o
$ nm -C test.o
                 U __gxx_personality_v0
0000000000000000 T main
                 U __stack_chk_fail
                 U _Unwind_Resume
                 U std::allocator<char>::allocator()
                 U std::allocator<char>::~allocator()
                 U std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)
                 U std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()

请注意对 __ cxx11的引用: * 。我认为这些是编译器插入的c ++ 11符号。我获得了成功的构建,但是显然使用了c ++ 11。这是ldd的输出:

Notice the references to __cxx11::*. I presume those are c++11 symbols that the compiler inserted. I get a successful build, but apparently using c++11. Here is the output from ldd:

$ ldd test
    linux-vdso.so.1 =>  (0x00007ffc381f5000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f6548d48000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f6548b32000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6548768000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f654845f000)
    /lib64/ld-linux-x86-64.so.2 (0x000055785493c000)

对于我的真实项目,我必须链接到c ++ 98的第三方库,但由于此编译器问题而无法这样做。我的目标文件正在这些库中寻找c ++ 11符号,但找不到它们。有任何见识吗?

For my real project, I have to link to third party libs that are c++98 but am unable to do so because of this compiler issue. My object files are looking for c++11 symbols in those libs but can't find them. Any insights?

推荐答案

此处中,libstdc ++ v.6支持新旧ABI。我必须将

As described here, the libstdc++ v.6 supports new and old ABI. I had to place

-D_GLIBCXX_USE_CXX11_ABI = 0

-D_GLIBCXX_USE_CXX11_ABI=0

放入Makefile的g ++命令中。那解决了lib不兼容的问题。

to the Makefile's g++ command. That took care of the lib incompatibility.

这篇关于gcc使用c ++ 11标准,即使明确指定了98的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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