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是只编译不链接

  • 相关阅读:
    HTML5基础
    错题本
    字符串
    带参的方法
    人际猜拳参考答案:
    用户登录页面——jdbc
    多媒体播放系统案例
    七言
    七言
    表格设计案例
  • 原文地址:https://www.cnblogs.com/fingertouch/p/2745620.html
Copyright © 2011-2022 走看看