C++ Resources

Updated on Nov 1  2020



C++CompilersCommandLineIDEsQuickSummary

Deborah R. Fowler



Summary Table for C++     ...   including Makefiles

Posted on  July 28  2013
Updated Sept 25  2023

Freeglut for Windows has been added to be consistent with our setup. I have tested it offsite with VS 2015
Professional, VS 2017 Community Versions and MinGW.
Currently glut is still used on linux.

Compilers/Command Line/IDE Summary Table (for more discussion see C++ Resources):

SUMMARY
On Windows
with OpenGL/glut (now use freeglut)
...freeglut
On Linux
with OpenGL/glut (now use freeglut)
...freeglut
Visual Studios 2019
here
VS 2010 with OpenGL/glut here
VS with freeglut
n/a
n/a
n/a
Eclipse
Eclipse on Windows
(see Eclipse on Windows)

Eclipse on Linux
(see Eclipse on Linux)
tba
Geany
Geany on Windows
(see Geany on Windows)

Geany on Linux
(see Geany on Linux)
tba
Command Line
c++ test.cpp -o test.exe
more about GNU here

** see note below
c++ test.cpp -o test.exe -lopengl32 -lglu32 -lglut32
more about OpenGL/glut here
mingw with freeglut
g++ test.cpp -o test.exe


** see note below
g++ test.cpp -o test.exe -lGL -lGLU -lglut
more about OpenGL/glut here
same
linux with freeglut
Makefile
mingw32-make
(example for tank)
(example for tank)
example zip
make
(example for tank - linux)
same
NOTE:
c++ or g++ are fine
recommend using -Wall
VS compiler default is fine
you can add more warnings by setting properties





Just because it compiles does not mean it is good code

A simple "hello world" makes a great test (see here).
I have also provided an example to test your OpenGL/glut set up here.

This is the same table provided on the C++ Resources page but is provided here for quick click convenience. I have personally tested all the combinations listed above either at Monty or on my home computer.

** Proper Usage Tip: you may want to add the flags  -pedantic -Wall        as well.
See note about wrong use of Arrays (use vectors if you want dynamic allocation).

** Silly Error Tip: the other day I typed in gcc instead of g++ Curious, I looked it up. gcc is the compiler for C, g++ is the compiler for C++ (not too surprising). An excellent examples of how C is a subset of C++ if you run g++ on both files Kermit.cpp and KermitOld.cpp it works, however gcc only works on KermitOld.cpp. If you run gcc on Kermit.cpp it fails because that file references libraries developed for C++ (iostream)

** Tip:
gcc or g++ will produce an a.out file if the -o flag is not used

** Tip: iomanip and things you can do to format cout coutOptions.cpp

** Troubleshooting Tip: note if you use the type numeric_limits in visual studios the compiler will recognize it, but command line (linux or mingw on windows) you will need to #include <limits>

** Troubleshooting Tip: M_PI is defined in "math.h" on linux, however it depends on which compiler you are using on Windows. If you are using mingw32-make in a command window it will recognize it, however Visual Studios project will not. You can test it on your own machine with this sample file here. One way to handle this is to add a define with an ifndef statement:
#ifndef M_PI
#define M_PI 3.141592654;
#endif
More recently, in VS2019 there are two solutions: place #define _USE_MATH_DEFINES as the very first include line (see KermitOld.cpp) or add _USE_MATH_DEFINES to the project properties/c c++/preprocessor definitions.

** Troubleshooting Tip: if you are splitting out your files into classes are are not using an IDE, please remember to use the #ifndef / #define / #endif syntax in your .h files and/or #pragma once. There is an excellent explanation here.
Some programmers believe it is safest to use both (see bottom of the thread here).

** Troubleshooting Tip: If you are using freeglut on Windows do not use the variable names far or near (http://sourceforge.net/p/freeglut/bugs/205/)

** Troubleshooting Tip: If you are are getting a "procedure entry point error at runtime" on Windows add the flag -static-libstdc++ to your compile command (https://stackoverflow.com/questions/38554987/mingw-boost-and-runtime-procedure-entry-point-could-not-be-located).
On my laptop this was not required 6/29/2019 but as of 10/01/2019 is or the libstd++6.dll can be copied into the directory.

** Troubleshooting Tip: If you should ever need to run Visual Studios without a shortcut:
2015 at Monty is in C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe
2017 on your Home Computer lives in C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE and you can use the CMD window to cd to that path and run devenv.exe

VS 2019 and 2022 Tip: If you want to suppress those warnings when you use a number and the compiler considers it a double, change your project properties:

Other options are to use one of the two methods below to type cast either by (float) or by small f after the number. This will not be a warning in some other IDEs but will appear in VS anytime you use a number with decimals.



It is also possible to suppress these warnings by using pragma (pragmaExample.cpp)




VS 2019 and VS 2022 Comments TIP:
MISSING IMAGE


Makefiles

With respect to makefiles, most IDEs have functionality that does not require you to create a makefile, however this becomes necessary if you are using multiple files with Geany. There is an excellent tutorial on Makefiles here. I have also provided an example make file above for both Windows and Linux for the OpenGL_TankTemplate starter game in the dropbox. There are step by step makefiles in the dropbox as well.