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

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

问题描述

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

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天全站免登陆