9

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
Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
Tieme
  • 62,602
  • 20
  • 102
  • 156
  • Why do you want to strip the binaries? Modern systems have so much space that it seems a bit redundant to remove the information. Also diagnosing problems on a stripped binary will be practically imposable. – Martin York Sep 13 '11 at 22:22
  • 2
    Why aren't you just saying `#include ` instead of the full path? – Mark B Sep 13 '11 at 22:58
  • @Tux-D one reason might be that it makes it harder to reverse engineer. – Seth Carnegie Sep 13 '11 at 23:03
  • - Tux-D Nice one but the reason is quite simple. Compiling, Executing and Stripping this simple program is an exercise listed in the c++ course which i enrolled. - Mark B, because than it will take the default iostream instead of my newly installed iostream which came with the gcc 4.6.0 compiler which is 255 bytes bigger.. – Tieme Sep 14 '11 at 14:36

2 Answers2

7

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".

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • okay, but apparently the files get some kind of stripping according to the filesize. Does that mean the system has two linkers? GCC linker & MACOS linker ? and one thinks its an obsolete option? – Tieme Sep 15 '11 at 10:53
  • @Tieme: I seriously doubt it. The MacOS `ld` does do some kinds of stripping; it just doesn't support `-s`. Does gcc *ever* not warn about the `-s` option? – Keith Thompson Sep 15 '11 at 17:08
2

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

Seth Carnegie
  • 73,875
  • 22
  • 181
  • 249