-1

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

2 Answers2

2

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.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
0

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