Building on the Command Line



Unix, Linux and MacOS users have the option of building C++ applications directly on the command line, just like I do during lectures.

MacOS users will need to make sure that Xcode is installed (even if you'd like to just use the command line). Unix/Linux users will need to make sure that gcc/g++ is installed.


When building from the command line, you need to manually specify which C++ standard you want to compile with and you also need to specify the standard runtime library to link with.


For MacOS users, this would take the following form:


clang -std=c++03 -lstdc++ -o main main.cpp


Where main is the name of the application binary that will be generated, and main.cpp is the name of the C++ file to compile.


For Unix/Linux users, you'd use a similar command, but the compiler is likely g++, like this:

g++ -std=c++03 -lstdc++ -o main main.cpp