zoukankan      html  css  js  c++  java
  • gcc 编译

    gcc main.c -o main
    gcc main.c -o ./output/main

    compile
    gcc -c main.c -o main.o

    link
    gcc main.o -o main.out

    ###############
    preprocess        .c--->.i
    compile            .i---> .s
    assemble        .s---> .o
    link            .o--->bin

    ##############

    -E
    -S
    -c
    -o

    -I directory
    -g

    -save-temps


    ####
    -c
    /* func.c */
    #include <stdio.h>
    void func_a()
    {
            printf("func_a ")
    }

    /* main.c */
    #include <stdio.h>
    int main(void)
    {
            func_a();
            func_b();
            return 0;
    }

    $ gcc -c func.c main.c >>> no error
    $ gcc func.c main.c >>> link error

    ####
    -E

    macro expansion
    file include

    gcc -E main.c -o main.i
    // -C
    //prevent preprocess from deleting comments
    gcc -E -C main.c -o main.i

    #####
    -S
    $ gcc -S main.c
    // variable name used comment in .s
    $ ggc -S -fverbose-asm main.c

    ####
    -l
    libc.a .a represent achieve
    libc.so .so share object
    /* main.c */
    #include <stdio.h>
    #include <math.h>
    #define PI 3.415926
    int main()
    {
            double param, result;
            param = 60.0;
            result = cos(param *PI /180.0);
            printf("The consine of %f degrees is %f. ", param, result);
            return 0;
    }

    //standard library
    // libm.a prefix lib suffix .a
    $ gcc main.c -o main.out -lm

    // other directory library
    1. used as object file
    $ gcc main.c -o main.out /usr/lib/libm.a
    2. -Lpath
    $ gcc main.c -o main.out -L/uar/lib -lm
    3.
    $ add path to environment LIBRARYPATH

    ##########
    gcc main.o func.o -o app.out -lm

    ########
    file type
    .c :
    .h : head file
    .i :
    .s : assemble
    .S : has c command, need to preprocess
    ########
    generate .so

    -shared
    -fPIC // Position-Independent Code
    $ gcc -fPIC -shared func.c -o libfunc.so

    $ gcc -fPIC -c func.c -o func.o // -fPIC used in compile stage
    $ gcc -shared func.o -o libfunc.so

    $ gcc main.c libfunc.so -o app.out

  • 相关阅读:
    集群
    监控流量脚本
    三次握手四次挥手的原理
    Nginx虚拟主机配置
    apche基于域名,ip,端口的配置
    LVS+Keepalived搭建MyCAT高可用负载均衡集群
    Codeforces 553E Kyoya and Train
    Codeforces 632E Thief in a Shop
    【BZOJ4259】残缺的字符串
    【BZOJ3160】万径人踪灭
  • 原文地址:https://www.cnblogs.com/youngvoice/p/11575307.html
Copyright © 2011-2022 走看看