G++编译器:选项 -s 已过时并被忽略 C++

发布于 2024-12-04 05:09:25 字数 705 浏览 4 评论 0原文

我正在尝试使用 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

I'm trying to compile and strip a very simple program in C++ with the g++ compiler (4.6.0 on Mac OSX). But while compiling i get a warning.


source code:

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

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

Terminal code:

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

Compiler warning:

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

Somebody any idea's about this weird warning?

Edit:

The weird thing is the size does decrease when using the -s flag, the decreases from 9,216 bytes to 9,008.

However when i use the following the size decreases to 8,896 bytes.

cp hello hello_stripped
strip hello_stripped

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你列表最软的妹 2024-12-11 05:09:25

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

gcc 传递 -s链接器的 选项,如 gcc 4.6.1 手册;显然,gcc 的 MacOS 端口仍然这样做。

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

-s 完全剥离输出,包括删除符号表。
不再支持此文件格式变体。这个选项是
已过时。

MacOS gcc 手册,与 GNU 的 gcc 手册不同,没有提到“-s”。

The error message is from ld, not from gcc or g++. (The gcc and g++ commands are drivers that invokes the compiler, the linker, and other tools.)

gcc passes the -s option to the linker, as documented in the gcc 4.6.1 manual; apparently the MacOS port of gcc still does that.

The GNU linker (GNU ld) still accepts the -s option with its usual meaning. But the MacOS linker (also called ld) ignores it, as documented in the 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.

And the MacOS gcc manual, unlike GNU's gcc manual, doesn't mention "-s".

将军与妓 2024-12-11 05:09:25

显然 -s 标志已过时。您可以使用 程序代替。

Apparently the -s flag is obsolete. You can use the strip program instead though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文