gcc using c++11 standard even though 98 explicitly specified

喜你入骨 提交于 2019-12-23 04:49:10

问题


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()

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)

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?


回答1:


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

-D_GLIBCXX_USE_CXX11_ABI=0

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



来源:https://stackoverflow.com/questions/42514202/gcc-using-c11-standard-even-though-98-explicitly-specified

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!