I don't think it's too bold to say that the answer to your question is no, in that you cannot get the command line arguments that were used to compile some arbitrary application. So I'm going to assume this is a program that you're building yourself.
Furthermore, no, there's no way to see the command line itself as a preprocessor macro.
Adding metadata to your executable
You can arrange for your build system to embed the build commands into your executable.
Firstly, you will want some mechanism for producing the embedded information itself. Here's one way:
make clean
make -n >buildinfo
Then, to embed the buildinfo in a text section of your ELF executable:
objcopy --add-section .build_info=buildinfo path_to_your_executable
You can extract this info again with:
readelf -p .build_info path_to_your_executable
or
objdump -s --section .build_info path_to_your_executable
For Windows
For Windows executables (PE files), you'll want to embed your build info as a custom resource, and you'll need your own custom way to extract it. The procedure is described in this answer.
Alternate route
If you want the build info available to the program itself, you can use xxd
.
For example:
xxd -i buildinfo >buildinfo.c
Fictional contents of buildinfo for illustration purposes:
Hello, world!
Resulting contents of buildinfo.c:
unsigned char buildinfo[] = {
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64,
0x21, 0x0a
};
unsigned int buildinfo_len = 14;
Just compile and link this file along with others in your program. Then you could manually write your command-line processing handling to include a flag like --show-build-info
that would output this string to stdout at run-time or put it in your about box or whatever is appropriate for your particular application.