How to compile linux

藏色散人
Release: 2019-11-11 09:11:32
Original
4335 people have browsed it

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");
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template