我正在尝试使用 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
,而不是来自 gcc
或 g++
。 (gcc
和 g++
命令是调用编译器、链接器和其他工具的驱动程序。)
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/