GCC compiler static libraries and dynamic library

㈠We know, GCC compiler principle of work

  1.Pre-Processing  head file *.h      ------------------------cpp -------Call CPP pretreatment
  2.Compiling                ------------------------cc1 -------Calls to compile the cc1, generation * . o suffix for target file
  3.Assembling             -----------------------as---------Call as compiled and assembly
  4.(Li(Linkiking))         -----------------------ld---------Call ld a link to it

⑵Common file extension

      .c                     C of original program

     .C/.cc/.cxx            C++ of original program

     .m                     Objjective-C of original program

     .i            The pretreatment of C has been original program

     .iiii                 The pretreatment of C++ has been original program

     .s/.S         Assembly language of original program

     .hh                    Pretreatment file pre-processing files

     .o                     object file

     .a//.so      Compiled a library file compiled a library file


⑶How to compile C file

  gcc - c hello.c ----------- hello.o (object file)

  gcc -c -o hello2.o hello.c --------hello2.o (object file)

  gcc -o hello hello.c ------------ hello (binary)

  gcc -o hello hello.o ------------ hello (binary)

            If have header files

  gcc -I/xxxxx -c -o ;

how to compiler static libraries and  dynamic library

                static library

   1. ar rv libhello.a hello.o XXX.o XXX.o --------------------libhello.a

               use static library
   2.gcc -o hello libhello.a --------------------------hello (binary)
   3.gcc -L. hello.o -lhello -o hello -----------------hello (binary)
   4.gcc -o  hello hello.c -L. -lXXXX ---------------hello(binary)
 
                dynamic library

    1.gcc -fPIC  -c hello.c  ------------------hello.o 
    2.gcc -shared -o libhello.so hello.o xxx.o  --------------libhello.so
                use dynameic library
   3.gcc -o hello -L. -lhello  ----------------------------hello(binary)
   4.gcc -o hello hello.c -L. -lxxxx 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值