Is there any option/pragma in gcc/mingw/mingw-w64 to add comment to the library/executable file (text string not affecting executing).
Analog of Microsoft and Borland #pragma comment (#pragma comment (exestr,"...")
and #pragma comment (user,"...")
The linker is ld
of mingw/mingw-w64 project

- 1,555
- 1
- 13
- 35
-
It also depends of the linker and operating system – Basile Starynkevitch Nov 19 '17 at 19:34
-
The linker is mingw32-make, the os is MS Windows. – Роман Коптев Nov 19 '17 at 19:35
-
That should go into your question. BTW `mingw32-make` is *not* a [linker](https://en.wikipedia.org/wiki/Linker_(computing)). It probably is some [build automation](https://en.wikipedia.org/wiki/Build_automation) tool – Basile Starynkevitch Nov 19 '17 at 19:36
-
@BasileStarynkevitch Ok, the linker is ld of mingw. The mingw and mingw-w64 are windows ports of gcc – Роман Коптев Nov 19 '17 at 19:38
-
I don't understand why you don't consider generating some C or C++ code for your needs. – Basile Starynkevitch Nov 19 '17 at 19:54
-
@BasileStarynkevitch Those pragmas generate 1) Text readable on top of exe file listing 2) Are shown with exe file properties (popup menu on exe file in file browser - info fields about author, licence and so on can be placed so) – Роман Коптев Nov 19 '17 at 19:59
-
`mingw32-make` is GNU Make, they choose that filename to avoid problems on systems that have a different `make` on the path already – M.M Nov 19 '17 at 21:40
2 Answers
You simply could add some global variable, e.g.
const char globname[] = "this comment";
You could even make it volatile
.
Perhaps you want to generate the globname
using some preprocessor tricks.
You could configure your build automation tool to compile some foo.cc
using e.g. g++ -Wall -g -Dsrcbasename=foo -c foo.cc
(how to do that is a different question) then define some macro in a common header myheader.hh
included everywhere like
#define FILE_ID_HERE(Str,Suf) const char glob_name_##Suf = Str
#define FILE_ID(Str) FILE_ID_HERE(Str,srcbasename)
and start your (and every) foo.cc
with things like
#include "myheader.hh"
FILE_ID("this comment");
or you might also improve your Makefile
to generate some timestamp file.
And some compilers accepted the #ident
directive.
And you might write your compiler plugin to understand your own #pragma
doing similar things. I don't think it is worth the effort.
Remember that some C or C++ code can be generated, but how to do that is your concern and depends more of your build procedure than of your compiler. Consider configuring your build automation tool for that purpose. If you use GNU make
or ninja
you just need to add a few rules for that.

- 223,805
- 18
- 296
- 547
Text information (like version info, copyrights, original file name and so on) can be added to exe/dll file by using versioninfo resources https://msdn.microsoft.com/en-us/library/aa381058.aspx
This information is readable whithin file explorer
Some IDE add such a file (usually resource.rc) to project automatically.

- 1,555
- 1
- 13
- 35