gcc 使用 c++11 标准,即使明确指定了 98
gcc using c++11 standard even though 98 explicitly specified
我收到一个奇怪的错误,我怀疑与我的系统配置有关。我是 compiling/linking 一个使用 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:
#include <string>
int main() {
std::string str = "Hello World!";
return 0;
}
这是我的编译和 link 命令(可能带有不必要的显式语言标准选项)和相关输出:
$ 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 的输出:
$ 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)
对于我的真实项目,我必须 link 到 c++98 的第三方库,但由于这个编译器问题而无法这样做。我的目标文件正在那些库中寻找 c++11 符号,但找不到它们。有什么见解吗?
如 here 所述,libstdc++ v.6 支持新旧 ABI。我必须放置
-D_GLIBCXX_USE_CXX11_ABI=0
Makefile 的 g++ 命令。这解决了 lib 不兼容问题。
我收到一个奇怪的错误,我怀疑与我的系统配置有关。我是 compiling/linking 一个使用 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:
#include <string>
int main() {
std::string str = "Hello World!";
return 0;
}
这是我的编译和 link 命令(可能带有不必要的显式语言标准选项)和相关输出:
$ 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 的输出:
$ 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)
对于我的真实项目,我必须 link 到 c++98 的第三方库,但由于这个编译器问题而无法这样做。我的目标文件正在那些库中寻找 c++11 符号,但找不到它们。有什么见解吗?
如 here 所述,libstdc++ v.6 支持新旧 ABI。我必须放置
-D_GLIBCXX_USE_CXX11_ABI=0
Makefile 的 g++ 命令。这解决了 lib 不兼容问题。