zoukankan      html  css  js  c++  java
  • Linux下编译程序

    一.编译C程序

    1.编译单个C程序:

    现编译如下程序(hello.c):

    #include<stdio.h>
    #include<stdlib.h>
    
    int main(int argc,char *argv[])
    {
        printf("Hello Linux!");
        return 0;
    } 
    

     使用:

    #gcc -o hello hello.c
    

    其中:-o选项是用来重命名程序名词,否则默认的程序名词为a.out

    2.编译多个源文件

    现同时编译两个文件(hello.h hello.c和main.c):

    //hello.h
    #ifndef __HELLO_H_
    #define __HELLO_H_
    
    void print(const char *word);
    
    #endif
    
    //hello.c
    #include<stdio.h>
    #include "hello.h"
    
    void print(const char *word)
    {
    printf("%s",word);
    }
    
    //main.c
    #include<stdio.h>
    #include<stdlib.h>
    #include"hello.h"
    int main(int argc,char *argv[])
    {
    print("hello Linux\n");
    return 0;
    } 
    

     编译此函数使用:

    #gcc -o hello hello.c main.c
    

     或者分步生成:

    #gcc -c hello.c
    #gcc -c main.c
    #gcc -o hello hello.o main.o
    

    其中,选项-c是只编译不链接

  • 相关阅读:
    6.11 修饰符的适用范围
    5.10 对象与垃圾回收
    5.9 枚举类
    5.8 java 11增强的Lambda表达式
    5.7 内部类
    5.6 接口
    5.5 抽象类
    5.4 final修饰符
    5.3 类成员
    5.2 Object类中两个需要被重写的方法
  • 原文地址:https://www.cnblogs.com/fingertouch/p/2745620.html
Copyright © 2011-2022 走看看