Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Take a look at the following command line:

gcc -o hello -Wall -D_BSD_SOURCE hello-world.c

Now, is there a way to know about these options by doing some processing on the 'hello' executable.

share|improve this question
up vote 3 down vote accepted

Sadly, no. But if you think about it before you create a binary, there are some ways. Here's another. With recent gcc, you can use -frecord-gcc-switches option which will add one section to the ELF file with the description you are seeking.

$ gcc -frecord-gcc-switches -o hello -Wall -D_BSD_SOURCE hello-world.c
$ readelf -p .GCC.command.line hello

String dump of section '.GCC.command.line':
  [     0]  -D _BSD_SOURCE
  [     f]  hello-world.c
  [    1d]  -mtune=generic
  [    2c]  -march=x86-64
  [    3a]  -Wall
  [    40]  -frecord-gcc-switches

As you can see it shows you all used options, not just those you provided explicitly.

share|improve this answer

Impossible, but compiler version might be available if you didn't strip the binary.

If you refer to the macro stuff, i.e #ifdef HAVE_XXX, it was recorded in the C/C++ source file. Take a look at GNU autogen tool chains.

share|improve this answer

No way, but if you use Makefile, there's a way:

CFLAGS=-Wall -D_BSD_SOURCE hello-world.c
    cc -o $(TARGET) $(CFLAGS) -DCFLAGS="\"$(CFLAGS)\""
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.