.o文件VS .a文件 [英] .o files vs .a files

查看:344
本文介绍了.o文件VS .a文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是什么这两种类型的文件之间的差异。我看到我的C ++可执行文件的施工过程中针对这两种类型的应用程序的链接。

What is the difference between these two file types. I see that my C++ app links against both types during the construction of the executable.

如何建立.a文件?链接,引用和特别的例子,是高度AP preciated。

How to build .a files? links, references, and especially examples, are highly appreciated.

推荐答案

的.o 文件的对象。他们是编译器和输入到链接器/库的输出。

.o files are objects. They are the output of the compiler and input to the linker/librarian.

.A 文件档案。它们是对象或静态库的基团,并且也输入到连接体。

.a files are archives. They are groups of objects or static libraries and are also input into the linker.

其他内容

我没有注意到你的问题的范例的一部分。一般来说,你将使用一个makefile生成静态库。

I didn't notice the "examples" part of your question. Generally you will be using a makefile to generate static libraries.

AR = ar 
CC = gcc

objects := hello.o world.o

libby.a: $(objects)
    $(AR) rcu $@ $(objects)

%.o: %.c
    $(CC) $(CFLAGS) -c $< -o $@

这将编译的hello.c world.c 成对象,然后将它们归档到库中。根据不同的平台上,您可能还需要运行一个称为公用 ranlib的来生成的存档目录。

This will compile hello.c and world.c into objects and then archive them into library. Depending on the platform, you may also need to run a utility called ranlib to generate the table of contents on the archive.

这是有趣的边注: .A 文件是技术上的存档文件的,而不是库。他们是类似,虽然他们使用一个更古老的文件格式压缩文件,而COM pression。通过实用工具,比如 ranlib的生成内容的表是什么使归档文件的的。 Java归档文件(的.jar )的,因为它们是具有由Java归档创造了一些特殊的目录结构的zip文件类似。

An interesting side note: .a files are technically archive files and not libraries. They are analogous to zip files without compression though they use a much older file format. The table of contents generated by utilities like ranlib is what makes an archive a library. Java archive files (.jar) are similar in that they are zip files that have some special directory structures created by the Java archiver.

这篇关于.o文件VS .a文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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