Skip to content

Compiling using GCC

mohsend edited this page Dec 2, 2014 · 5 revisions

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

g++ -o "executable_name" "code_file.cpp"

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

g++ -Wall -o "executable_name" "code_file.cpp"

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

cd projects/cpp-examples/mabani/

then compile!

g++ -Wall -o "test" "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:

./test

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

Clone this wiki locally