c++ - G++ 编译器 : option -s is obsolete and being ignored C++

标签 c++ macos g++

我正在尝试使用 g++ 编译器(在 Mac OSX 上为 4.6.0)在 C++ 中编译和剥离一个非常简单的程序。但是在编译时我收到警告。


源代码:

#include </usr/local/Cellar/gcc/4.6.0/gcc/include/c++/4.6.0/iostream>

int main(){
    std::cout << ("Hello World\n") ;
}

终端代码:

g++ hello.cc -Wall -std=c++0x -s
    /* or an alternative: */
g++ hello.cc -Wall -std=c++0x -o test -Wl,-s

编译器警告:

ld: warning: option -s is obsolete and being ignored

有人知道这个奇怪的警告吗?

编辑:

奇怪的是当使用 -s 标志时,大小确实减少了,从 9,216 字节减少到 9,008 字节。

但是,当我使用以下内容时,大小会减少到 8,896 字节。

cp hello hello_stripped
strip hello_stripped

最佳答案

错误消息来自 ld,而不是来自 gccg++。 (gccg++ 命令是调用编译器、链接器和其他工具的驱动程序。)

gcc-s 选项传递给链接器,如 gcc 4.6.1 manual 中所述;显然,gcc 的 MacOS 端口仍然可以做到这一点。

GNU 链接器 (GNU ld) 仍然接受具有通常含义的 -s 选项。但是 MacOS 链接器(也称为 ld)会忽略它,如 MacOS ld manual 中所述。 :

-s Completely strip the output, including removing the symbol table. This file format variant is no longer supported. This option is obsolete.

还有 MacOS gcc manual ,不像 GNU 的 gcc 手册,没有提到“-s”。

关于c++ - G++ 编译器 : option -s is obsolete and being ignored C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7408692/

相关文章:

c++ - 在类模板方法中使用enable_if来检查两个函数参数是否都是std::array或都是std::vector

c++ - 如何同时使用变量和 move 变量?

macos - kubectl -bash : _init_completion: command not found

c++ - C++ 中的名称冲突

c++ - 在 C++ 中,当我对 -128,127 范围之外的整数值使用 static_cast<char> 时会发生什么?

g++ - 在ubuntu上为arm交叉编译Boost 1.57.0

c++ - QQmlEngine 和 cmake

c++ - 在opengl中寻找旋转图像的中心

macos - 从 shell 打开终端并执行命令

python - wxPython 在 THIThemeTextInfoPublic::GetOptions() const + 9 处随机崩溃