Is there any way to find out, whether the executable is compiled with
-g option enabled?
The C standard has no knowledge of compile options, so any
answer would have to be system dependant, for the system type
you did not specify.
What's the -g option anyhow? On SGI's IRIX cc compiler,
the -g option has to do with the variety of debugging information
produced, and with whether some optimizations will be allowed even
though they make the debugging information less accurate. The
default for IRIX's cc is -g0 -- so *every* program compiled with
IRIX's cc is "compiled with -g option enabled".
gcc has a suite of -g options, which control what the format of
debugging information is, but the man page talks in terms of
"extra" debugging information. I guess for at least some versions
of gcc, it is meaningful to ask whether the -extra- debugging
information has been included.
One of the items normally included in the output of IRIX's objects is
a copy of the command line argument used for the compilation. This
is especially useful for C++ compilations in order to [automatically]
detect whether a pre-compiled template was compiled with compatable
arguments and so may be reused without having to be regenerated.
Possibly your system has something similar, and possibly your
system provides a non-standard extension such as libdwarf or
libelf to allow you to probe the headers from within a program.
But if you just want a one-shot check, then you may wish to
investigate whether your system supports a program such as
elfdump or dwarfdump, or whether your system has a version of
'nm' that will give up the information. And there's always "strings"
on the executable ;-)