C语言 什么是扩展名为 .a 的文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5965171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 08:37:44  来源:igfitidea点击:

What is a file with extension .a?

cgccshared-libraries

提问by Blub

I downloaded this: https://github.com/mongodb/mongo-c-driver

我下载了这个:https: //github.com/mongodb/mongo-c-driver

And now I'm trying to use it inside my C program, but I don't know what to do with the generated .a files. What are they? I couldn't find any information, not even in the GCC manual.

现在我试图在我的 C 程序中使用它,但我不知道如何处理生成的 .a 文件。这些是什么?我找不到任何信息,甚至在 GCC 手册中也找不到。

And I built it like so:

我是这样构建的:

  scons --c99

Also, can I use C99libraries with my C89 program?

另外,我可以在我的 C89 程序中使用C99库吗?

回答by GWW

.afiles are staticlibraries typically generated by the archive tool. You usually include the header files associated with that static library and then link to the library when you are compiling.

.a文件是通常由归档工具生成的静态库。您通常包含与该静态库关联的头文件,然后在编译时链接到该库。

回答by Sriram

.afiles are created with the arutility, and they are libraries. To use it with gcc, collect all .a filesin a lib/folder and then link with -L lib/and -l<name of specific library>.

.a文件是使用该ar实用程序创建的,它们是库。要与 一起使用,请将gcc所有内容收集.a files在一个lib/文件夹中,然后与-L lib/和链接-l<name of specific library>

Collection of all .a files into lib/is optional. Doing so makes for better looking directories with nice separation of code and libraries, IMHO.

收集所有 .a 文件lib/是可选的。这样做可以使目录看起来更好,代码和库的分离很好,恕我直言。