The method of compiling and running C and C++ programs on Linux
Editor to share with you how to compile and run C and C++ programs on Linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
C is a powerful programming language for developing system software. This article will introduce you to running C and C + + programs on Linux systems from the command line. In this article, we use the 'gcc' and' g + + 'commands of GCC (GNU Compiler Collection) to compile C / C + + programs.
Gcc is the GNU C compiler in GCC.
G + + is the GNU C + + compiler in GCC.
Install development tools
To run the C program, you must have a development kit installed on the Linux system. Run one of the following commands to install the development kit based on your operating system.
$sudo yum groupinstall "Development Tools" # # Redhat-based system $sudo apt-get install build-essential # # Debian-based system
C language example
For example, write code for Hello World.
# include int main () {printf ("Hello World!"); return 0;}
Create a new file on the system, as follows:
$vim helloworld.c
Compile and run C / C + + programs in Linux
Compile the above hello world program using the GNU C compiler as follows:
$gcc helloworld.c-o hello
Use C + + to compile the following commands.
$helloworld.c + helloworld.c-o hello
The above command creates an executable file named hello in the current directory. You can directly run the same operation as other commands
$. / hello
You can also copy files in the bin directory (/ usr / local / bin) to make them system-wide accessible.
The above is all the methods of compiling and running C and C++ programs on Linux. Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!