Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which C++ compiler is my program using?

I am not very expert in cpp programming, rather a beginner in the enormous world of programming, as these days we just install any IDE and start with our programs in it. I started using CodeBlocks IDE but just out of curiosity wanted to know which compiler is my program using as it can be 4.3.2 or 4.0.8 or maybe something else

I tried reading through the Build logs it wasn't there, a small google did not help either.

Is there any simple command which i can run in my cpp progam and check which compiler my IDE is using?

Thanks in advance.

like image 690
Dharamveer Singh Chouhan Avatar asked Aug 06 '11 17:08

Dharamveer Singh Chouhan


People also ask

How do I know which C compiler I have?

Type “gcc –version” in command prompt to check whether C compiler is installed in your machine.

Which compiler is used for C programming?

There are many compilers for C, but we will focus on a free open source version called the Gnu C compiler. (Actually we will use the Gnu C++ compiler, but all C programs compile using this compiler).

Which C compiler is used in Windows?

If you want to run C or C++ programs in your Windows operating system, then you need to have the right compilers. The MinGW compiler is a well known and widely used software for installing GCC and G++ compilers for the C and C++ programming languages.

How do I know which compiler I am using in Visual Studio?

You can select the compiler and corresponding toolset that will be used to build a project with the “Platform Toolset” property under General Configuration Properties for C++ projects. Any installed compilers that are applicable to your project type will be listed in the “Platform Toolset” dropdown.


2 Answers

You can use the macros

__GNUC__
__GNUC_MINOR__
__GNUC_PATCHLEVEL__

See http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html

Other compilers provide their own macros, for example Microsoft's _MSC_VER

Here's a very comprehensive list covering dozens of compilers: http://predef.sourceforge.net/precomp.html and http://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers

like image 188
Ben Voigt Avatar answered Sep 21 '22 17:09

Ben Voigt


According to the Codeblocks FAQ:

As a matter of fact it largely depends on the used compiler plugin. Some provided with the default Code::Blocks installation are GNU GCC (MinGW/Cygwin), MS Visual C++ Free Toolkit 2003, Borland's C++ Compiler 5.5, DigitalMars Free Compiler., OpenWatcom, Small Device C Compiler (SDCC) and others.

like image 24
Chris Eberle Avatar answered Sep 20 '22 17:09

Chris Eberle