Home  >  Article  >  Operation and Maintenance  >  How to compile linux

How to compile linux

藏色散人
藏色散人Original
2019-11-11 09:11:324282browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to save in LinuxNext article:How to save in Linux