?
Solved

Finding Compiler Version from C++ Object Code

Posted on 2006-06-12
13
Medium Priority
?
413 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 800 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 1200 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 1200 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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

752 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