I am new to Linux. I am using Ubuntu 11.04 and do not know how to compile and execute C++ program in it. I need to know the commands to Compile and Execute a C++ program in Linux.
To compile your c++ code, use:
foo.c in the example is the name of the program to be compiled.
This will produce an executable in the same directory called
g++ should already be in your $PATH, so you don't need to call
As noted by @con-f-use, the compiler will usually make this file executable, but if not, you can do this yourself (so the command to execute,
To specify the name of the compiled output file, so that it is not named
This will compile
I'm making two assumptions here:
The simplest way to compile a C++ program on Ubuntu, or any other Linux distro for that matter, is to type
The above commands assume you are already in the location of the source files, but both the source file and target output file may also be specified as a directory. For example
will compile a C++ source file located on your desktop and place the executable binary in a
You need g++,for gcc may can't compile cpp file easily.