Solved

Finding Compiler Version from C++ Object Code

Posted on 2006-06-12
13
403 Views
Last Modified: 2012-06-21
Hi, Is there a way to find out what compiler and version was used to produce C and C++ object code.  I also have the source code and found out that "std namespace" was not used.

Thanks, Allan
0
Comment
Question by:huffmana
  • 5
  • 4
  • 3
  • +1
13 Comments
 

Author Comment

by:huffmana
ID: 16886904
The Makefiile looks like this....

LD = g++
CC = g++
CDS-INCLUDE = /h/DII_DEV/include
CDS-LIB = /h/COE/Comp/CDS/lib
LDFLAGS = -L$(CDS-LIB) -lCDS
CFLAGS = -g -Wall

OBJS = \
../adapters/cds/cdsSource.o\
../adapters/cds/orderableItem.o\
../cdsHelper/cdsDeleteClasses.o\
../cdsHelper/cdsDeleteObjects.o\
../cdsHelper/cdsDeleteOneObject.o\
../cdsHelper/cdsDeleteTree.o\
../cdsHelper/getCDSNameDepth.o\
../resolver/contMenus.o\
../resolver/getFeatures.o\
../util/cdsListValue.o\
../util/cdsObject.o\
../util/stringToUl.o\
../util/ulToString.o

LIBS = -L$(CDS-LIB) -lCDS

programs = \
 SMB_cleaner

SMB_cleaner: SMB_cleaner.o ${OBJS}
        ${LD} ${LDFLAGS} SMB_cleaner.o ${OBJS} ${LIBS} -o SMB_cleaner

0
 
LVL 17

Assisted Solution

by:rstaveley
rstaveley earned 200 total points
ID: 16886950
> g++

That would be GNU C++, but I don't believe you can find out the version from the .o files.

>  I also have the source code and found out that "std namespace" was not used

Try putting into a global include...

    using namespace std;

....and compiling it with a modern version of GNU C++, and you may be in business. Do expect a few compilation errors/warnings to address.
0
 
LVL 86

Accepted Solution

by:
jkr earned 300 total points
ID: 16886957
That will depend. If you are building the files, adding a

#pragma comment(compiler)

(VC++)

will take care of placing that information in the binaries. If not, all you can do is hope that the compiler that was used did that.

Another hint might be the version of e.g. runtime DLLs the binaries rely on (see e.g. the DependecyWalker from www.dependecywalker.com).
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:huffmana
ID: 16886994
TIme is the fire in which we burn - STAR TREK

Because of the changes needed to add namespace (I have other experts-exchange questions about this) there is an great interest to go back to the original compiler.  This idea is that we need to run under both the Solaris 8 and 10 standard installations and we are afraid that the latest gcc will not run under Solaris 8.....  Does this make sense?  Thanks, Allan

0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 300 total points
ID: 16887164
>>we are afraid that the latest gcc will not run under Solaris 8

Not necessary to be afraid - see

http://www.sunfreeware.com/sol8right.html

and

http://www.sunfreeware.com/programlistsparc8.html#gcc34

Which GCC version are you using now? BTW, GCC 3.4.2 definitely conforms to ANSI C++, so your code will definitely compile if you didn't use any exotic features.
0
 

Author Comment

by:huffmana
ID: 16887700
Also I would have to find out the --compile options even if I traced it to the original gcc version.  For now I'm going to keep going with gcc 3.4.2.  Now that I have gotten over the struct problem (see the following) :-}  Note that the struct had to be put explicity into the std namespace!!  
Thanks everyone for your help.  Best Regards, Allan

using namespace std;              // added Allan

namespace std                        // added Allan
{                                            // added Allan
template <>
struct less<MenuID>
  : public binary_function<MenuID, MenuID, bool>
{
        bool operator()(const MenuID & mid1, const MenuID & mid2) const
        {
                if (
  .
  .
  .
        }
};

}                           // added Allan

0
 
LVL 86

Expert Comment

by:jkr
ID: 16887733
>>Note that the struct had to be put explicity into the std namespace!!

Yes, that was clear from your previous Q.
0
 

Author Comment

by:huffmana
ID: 16887842
Sorry JKR, I should have noticed that that was you.  I should have referenced that question and not acted like I solved the problem on my own.  Sorry for the faux-pas. Allan
0
 
LVL 86

Expert Comment

by:jkr
ID: 16888242
Never mind ;o)
0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 16888308
When using gcc, the following macros are predefined.  You can use them to assemble a compiler version string that you embed in the .o files (as a static string constant).  Once the compiler version is embedded within the .o file, you can use something like the 'strings' command to extract it.

__GNUC__
This macro is defined if and only if this is GNU C. This macro is defined only when the entire GNU C compiler is in use; if you invoke the preprocessor directly, `__GNUC__' is undefined. The value identifies the major version number of GNU CC (`1' for GNU CC version 1, which is now obsolete, and `2' for version 2).

__GNUC_MINOR__
The macro contains the minor version number of the compiler. This can be used to work around differences between different releases of the compiler (for example, if GCC 2.6.x is known to support a feature, you can test for __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 6)).

__GNUC_PATCHLEVEL__
This macro contains the patch level of the compiler. This can be used to work around differences between different patch level releases of the compiler (for example, if GCC 2.6.2 is known to contain a bug, whereas GCC 2.6.3 contains a fix, and you have code which can workaround the problem depending on whether the bug is fixed or not, you can test for __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 6) || (__GNUC__ == 2 && __GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ >= 3)).

__GNUG__
The GNU C compiler defines this when the compilation language is C++; use `__GNUG__' to distinguish between GNU C and GNU C++.


Given the above, I managed to stringify the version using some macros:

#ifdef __GNUC__
#define COMP_VER_STR(x) COMP_VER_XSTR(x)
#define COMP_VER_XSTR(x) #x
#ifdef __GNUG__
  #define COMP_NAME g++
#else
 #define COMP_NAME gcc
#endif
static char compiler_version[] = COMP_VER_STR(COMP_NAME) " " COMP_VER_STR(__GNUC__) "." COMP_VER_ST\
R(__GNUC_MINOR__) "." COMP_VER_STR(__GNUC_PATCHLEVEL__) "";
#undef COMP_NAME
#undef COMP_VER_XSTR
#undef COMP_VER_STR
#endif

#include <stdio.h>

int main()
{
  printf("compiler version: %s\n", compiler_version);
  return 0;
}


Obviously, I would create a header file that hides all this ugliness and gets included into all your source files:


#include <stdio.h>
#include "comp_ver.h"

int main()
{
  printf("compiler version: %s\n", compiler_version);
  return 0;
}

0
 

Author Comment

by:huffmana
ID: 16888579
Beautiful, that is what is really needed.  I should like to use your code to imbed the compiler into the binary !!  With your permission.  I'll be happy to add your name :-)

I noticed that the application does check for __GNUC__ but only checks for GNU and does not verify a miminum version number...  and it doesn't keep the results.

Looks Super !!!  Allan



0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 16890343
No problem.
0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 16890395
Also note that the \ linebreak was unintended.  It was a copy-paste artifact.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question