G++ compiler: option -s is obsolete and being ignored C++

蹲街弑〆低调 提交于 2021-02-07 14:31:28

问题


I'm trying to compile and strip a very simple programm in C++ with the g++ compiler (4.6.0 on Mac OSX). But while compiling i get an 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

回答1:


The error message is from ld, not from gcc or g++. (The gcc and g++ commands are a 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".




回答2:


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



来源:https://stackoverflow.com/questions/7408692/g-compiler-option-s-is-obsolete-and-being-ignored-c

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