Reputation: 131
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.
Upvotes: 10
Views: 10897
Reputation: 6608
Code::Blocks is a very generic IDE that can use many compilers. You can even have different compilers for every project.
Depending on what version you have installed (I have the Nov 11 2009 build, running under Windows) when you have a project loaded you can go to the "Project menu" -> "Build options" item and you will see what compiler you are using for that project - keep a note of it. Close that window and then go to the "Settings" menu -> "Compiler and debugger..." item. In the window it brings up make sure you have the "Global compiler settings" icon selected from the list on the left. Change to the "Toolchain executables" page from which you can get the exact path to the compiler executable that your project is using by making sure the "Selected compiler" drop down box at the top of the screen matches the one for your project".
The other way to get that information is to build your project, then switch to the "Build log". The command line should at least have the compiler executable as part of the filename it shows.
From the compiler filename you can then detemine whether it is some sort of GCC derivative or something else (such as MSVC). At this point it becomes compiler specific to find out what version you are using. For example, if it is GCC or a port then you can run:
<path and filename of compiler> --version
from a command prompt/shell to get the version number.
If it is MSVC, then simply running:
<path and filename of compiler>
will display the version number.
If you want to do it from your compiler (although technically it will be the preprocessor) you will need to know the above information to know what your compiler is, as you need to know the preprocessor macros to check for, which are compiler dependant.
On the plus side, Code::Blocks is likely to use GCC unless you have specifically downloaded the version without MinGW on Windows. So you are probably OK to use the method Ben Voigt describes.
Edit: missing line breaks hid the compiler version command lines
Upvotes: 3
Reputation: 283604
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
Upvotes: 4
Reputation: 96119
Probably not, there are various macros defined by the programming environment (giving version of the OS/SDKs etc) but these are normally set by include files rather than the compiler.
The compiler might define it's own symbols but you would have to check the compiler docs.
You could check the path and try running the compiler (typically cc or cl) with a "-v" or "/?" flag to see what it reports
Upvotes: 1
Reputation: 48765
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.
Upvotes: 2