This article will show you how to compile a C/C++ program in Ubuntu/Kubuntu/Xubuntu using the gcc/g++ compiler. Except from step one which is specific for Debian based distribution, the steps should apply to any Linux distro. In this article we will assume that you have the file containing the code on the Desktop and that it's named hello.c or hello.cpp
- Install the build-essential package by typing the following command in the terminal: sudo apt-get install build-essential.
C/C++ compiler testsuite
SuperTest: The most complete C/C++ compiler test suite in existence
www.ace.nl - 2Now create a file that has the extension .c (if you plan to write a C program) or .cpp (for a C++ program).
- 3Write the code in that file.
- 4Now open a terminal and go to the place where you saved that file using the cd command (e.g. cd Desktop).
- 5If you have a C program type in the terminal
- gcc -Wall -W -Werror hello.c -o hello.
- The first line will invoke the GNU C compiler to compile the file hello.c and output (-o) it to an executable called hello.
- The options -Wall -W and -Werror instruct the compiler to check for warnings.
- gcc -Wall -W -Werror hello.c -o hello.
- 6If you have a C++ program simply replace gcc with g++ and hello.c with hello.cpp. The options do the same things.
- 7If you get a permissions error, you need to make the file executable. You can do this with chmod +x hello.cpp
- 8Now type in the terminal ./hello and the program will run.
0 comments:
Post a Comment