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

  • 相关阅读:
    Java Singleton 单例模式
    android 让真机显示 DeBug Log调试信息
    android 图片处理经验分享
    android GridView 的使用 实现多项选择
    Spark/Storm/Flink
    Https
    Netty
    Netty
    java 线程状态相关测试
    Socket buffer 调优相关
  • 原文地址:https://www.cnblogs.com/fingertouch/p/2745620.html
Copyright © 2011-2022 走看看