Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

3 Answers

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
add comment

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
add comment

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

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

Your Answer

 
discard

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.