LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Version Info Coded Into ELF Binary (https://www.linuxquestions.org/questions/programming-9/version-info-coded-into-elf-binary-847430/)

Peter_APIIT 11-30-2010 06:00 AM

Version Info Coded Into ELF Binary
 
Hello to all,

How to coded version info and other information likes author and company name into the ELF binary ?

I prefer the put the version info during build step.

Thanks.

theNbomr 11-30-2010 10:44 AM

In C, I use a scheme in which a static string is made to contain CVS tags, and which are expanded when the file is committed to the repository:
Code:

static char[] filename_c = "$Id$  $Source$";
When appropriate, there may be a command to display the string(s), or running the strings command against the binary displays the string.
I'm lead to believe that the same method is possible with other revision control systems.

--- rod.

Peter_APIIT 12-01-2010 02:23 AM

Quote:

Originally Posted by theNbomr (Post 4175940)
In C, I use a scheme in which a static string is made to contain CVS tags, and which are expanded when the file is committed to the repository:
Code:

static char[] filename_c = "$Id$  $Source$";
When appropriate, there may be a command to display the string(s), or running the strings command against the binary displays the string.
I'm lead to believe that the same method is possible with other revision control systems.

--- rod.

I also follow your approach but with different tortoise svn/rabbit cvs software.
Below is my code:

Code:

void DisplayVersionInfo()
{
        const char* version = "v1.0";

        std::cout << "Web-MC Version : " << version << std::endl;

}

I query the version info from command line like below.
Code:

  if(argc >= 2)
    {
            if(atoi(argv[1]) == 1)
            {
                    std::cout << "Starting the processor as Master\n";
                    Processor::instance().initializeProcess(0, pmsmMaster, 8080);
            }
            else if(!strcmp(argv[1], "--version"))
            {
                    DisplayVersionInfo();
                    exit(0);
            }
            else
            {
                    std::cout << "Starting the processor as Slave\n";
                    Processor::instance().initializeProcess(1, pmsmSlave, 8181);
            }
    }

Anyone got idea how to do this in svn ?

Thanks.

Peter_APIIT 12-13-2010 08:47 PM

Please help.

paulsm4 12-13-2010 11:59 PM

Hi -

theNbomr *did* help you!

Q: What's wrong with his suggestion, or what don't you understand?

PS:
If you're unfamiliar with how the CVS keywords "$Id" or "$Source" (among others) might relate to Subversion, this link might help:

http://svnbook.red-bean.com/en/1.5/s....keywords.html

theNbomr 12-14-2010 01:10 PM

Thanks for that paulsm4. I thought I must have misunderstood the question. Just to expand on my earlier post, I will add some of the details. Regretably, my first example did not use optimal CVS keywords, and do not match the ones I use routinely.
Code:

static char[] filename_c = "\nfilename.c: $Revision$ $Date$\n";
The variable named 'filename_c' is the C source file name, with the '.' replaced with an underscore. When I commit the source code to CVS, the macros/tokens "$Revision$" and "$Date$" are expanded by CVS into strings that identify the respective information about the file:
Code:

static char[] filename_c = "\nfilename.c: $Revision: 1.2 $ $Date: 2009/08/20 23:45:03 $\n";
When this source module is then compiled and linked into the runtime binary, it will have the above string embedded into it. As I said before, running the strings command against that binary will display the embedded string. If you want to, your program can provide a command of some sort, such as a '--version' option that will printf() the string(s), or display them in some other manner. If the C module is used to build a library, the contents of the library can be examined with the nm command, and when filtered with grep:
Code:

nm libMyLibrary.so | grep "_c"
will display all of the filenames that are similarly massaged within the library.

Hope this clarifies my original post.

--- rod.

EDIT: You can put a rule in your Makefile to commit all sources to CVS (or whatever versioning tool you use), thus satisfying your build-time requirement.


All times are GMT -5. The time now is 04:14 AM.