Solved

Finding Compiler Version from C++ Object Code

Posted on 2006-06-12
13
411 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

696 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