How to Compile C++ on Linux
Most people that program in C and C++ do their scripting, compiling and running on Windows machines. There are many compilers for Windows, the most popular of which is probably Microsoft's Visual Studio, a multi-featured software program.
If you do your C++ programming on a Linux machine, you cannot use Visual Studio, as it is a Windows-only program. However, you can compile and run your programs without paying for a compiler, using the free g++ compiler package.
Instructions
-
-
1
Open a terminal. At the prompt, type "g++ -v". If you have the g++ compiler package installed on your machine, this should return the compiler package version. On the other hand, if it returns an error, you must download and install the package. Refer to your documentation, as the procedure for doing this may vary according to your distribution. In Ubuntu, for example, type "sudo apt-get install g++" at the prompt to install the compiler. You may also open your distribution's package manager and look for the g++ package.
-
2
Navigate to the directory where your C++ script is stored.
-
-
3
Type "g++ sample_script.cpp" to compile the script. This will create an executable file, "a.out," in the same directory as the original script.
-
4
Type "./a.out" in order to run the executable.
-
1