GCC compiler static libraries and dynamic library

来源:互联网 发布:刘姥姥性格知乎 编辑:程序博客网 时间:2024/05/29 14:31

㈠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 


原创粉丝点击