What's the difference between object file and static library(archive file)?

前端 未结 1 1554
[愿得一人]
[愿得一人] 2021-02-05 05:21

Seems archive file can be generated from object file:

ar rvs libprofile.a profile.o

What\'s the difference between object file and archive file

相关标签:
1条回答
  • 2021-02-05 05:49

    The static library is a collection of one or more object files, with an index to allow rapid searching. There are some minor differences in how the compiler deals with them. With an object file you link like this:

    gcc f1.o f2.o -o myexe
    

    with libraries you can also do that:

    gcc f1.o libf2.a -o myexe
    

    or you can use shorthand:

    gcc d1.o -lf2 -L. -o myexe
    

    Also, gcc will ALWAYS link .o files, but it will only search libraries and link from them if there are undefined names still to resolve.

    0 讨论(0)
提交回复
热议问题