Skip to content

Compiling using GCC

Mohsen Dastjerdi Zade edited this page May 30, 2015 · 5 revisions

Easiest way to compile in *nix (Linux, OS X, freeBSD,...) is using GCC. after installing GCC, to compile run this command in terminal:

g++ "code_file.cpp"

But i recommend using -Wall flag to see more warnings and errors for sloppy codes. like this:

g++ -Wall "code_file.cpp"

For example lets compile hello_func.cpp. first head to the working directory. like this:

cd projects/Magnificent-University-Projects/101-Fundamentals/

then compile!

g++ -Wall "hello_func.cpp"

all done! to run the executable just type the path of the executable. if it's in the same directory as the current path of terminal, you can run it like this:

./a.out

the dot means the current directory, and a.out is the name of our executable.

if you want to give your executable an specific name, use the -o flag:

g++ -Wall -o "test" "hello_func.cpp"
Clone this wiki locally