Home > Article > Operation and Maintenance > How to compile linux
How to compile Linux?
Compile and run C program under Linux
1. Execute vim demo.c to write C language file
Recommendation: " Linux tutorial》
#include<stdio.h> int add(int,int); int add(int num1,int num2) { return num1+num2; } void main() { int res=0; res = add(2,3); printf("%d\n",res); printf("哈哈\n"); }
2. After writing: wq save and exit, enter gcc -o demo demo.c (PS: By default, after the compilation is successfully completed, it will be in the current path, Generate a file named a.out, and then execute ./a.out to print the results, but you can usually specify your own executable program name through the option -o;)
3. Compilation completed successfully Finally, generate a file named hello under the current path, and then execute ./demo to see the output 5 and haha.
The above is the detailed content of How to compile linux. For more information, please follow other related articles on the PHP Chinese website!