• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 425
  • Last Modified:

Finding Compiler Version from C++ Object Code

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
huffmana
Asked:
huffmana
  • 5
  • 4
  • 3
  • +1
3 Solutions
 
huffmanaAuthor Commented:
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
 
rstaveleyCommented:
> 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
 
jkrCommented:
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
Technology Partners: 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!

 
huffmanaAuthor Commented:
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
 
jkrCommented:
>>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
 
huffmanaAuthor Commented:
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
 
jkrCommented:
>>Note that the struct had to be put explicity into the std namespace!!

Yes, that was clear from your previous Q.
0
 
huffmanaAuthor Commented:
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
 
jkrCommented:
Never mind ;o)
0
 
brettmjohnsonCommented:
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
 
huffmanaAuthor Commented:
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
 
brettmjohnsonCommented:
No problem.
0
 
brettmjohnsonCommented:
Also note that the \ linebreak was unintended.  It was a copy-paste artifact.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now