LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-30-2010, 06:00 AM   #1
Peter_APIIT
Member
 
Registered: Dec 2006
Posts: 606

Rep: Reputation: 31
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.

Last edited by Peter_APIIT; 11-30-2010 at 06:03 AM.
 
Old 11-30-2010, 10:44 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.

Last edited by theNbomr; 11-30-2010 at 10:47 AM.
 
Old 12-01-2010, 02:23 AM   #3
Peter_APIIT
Member
 
Registered: Dec 2006
Posts: 606

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by theNbomr View Post
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.
 
Old 12-13-2010, 08:47 PM   #4
Peter_APIIT
Member
 
Registered: Dec 2006
Posts: 606

Original Poster
Rep: Reputation: 31
Please help.
 
Old 12-13-2010, 11:59 PM   #5
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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

Last edited by paulsm4; 12-14-2010 at 12:03 AM.
 
Old 12-14-2010, 01:10 PM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.

Last edited by theNbomr; 12-14-2010 at 08:25 PM.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Execute the ELF Binary which already resides inside the memory bloomstar7 Programming 17 05-21-2010 05:55 AM
how to make difference between debuggable version of ELF and stripped binary dayalan_cse Programming 1 11-13-2008 06:52 AM
How can I find out if libraries are hard coded into the binary (QT specificly) drkstr Slackware 8 06-18-2006 08:35 PM
How to compile into ELF binary? kornerr Programming 3 06-29-2005 11:37 AM
Reading Memory Value from ELF Binary Damaged Soul Programming 4 11-24-2004 11:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration