目标文件和静态库(归档文件)有什么区别? [英] What's the difference between object file and static library(archive file)?

查看:352
本文介绍了目标文件和静态库(归档文件)有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎可以从目标文件生成归档文件:

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?

在我看来,两者都可以直接与gcc一起使用,例如:

It seems to me that both can be used with gcc directly,e.g.:

gcc *.c profile.ogcc *.c libprofile.a

有什么区别?

推荐答案

静态库是一个或多个目标文件的集合,并带有允许快速搜索的索引.编译器处理它们的方式略有不同.使用目标文件,您可以这样链接:

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

或者您可以使用速记:

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

此外,gcc总是会链接.o文件,但是,如果还有待解决的未定义名称,它将仅搜索库并从它们进行链接.

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.

这篇关于目标文件和静态库(归档文件)有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆