如何在Linux中编译静态库? [英] How to compile a static library in linux?

查看:187
本文介绍了如何在Linux中编译静态库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题:如何使用gcc在linux中编译静态库,即我需要将我的源代码编译到名为out.a的文件中。用命令 gcc -o out.a out.c 来编译就足够了吗?我不太熟悉gcc,希望任何人都可以帮我一把。 解决方案

请参阅使用gnu编译器[gcc]创建共享库和静态库

  gcc -c -o out.o out.c 

-c 表示创建中间目标文件,而不是可执行文件。

  ar rcs libout.a out.o 

这将创建静态库。 r 表示用替换插入, c 表示创建一个新的存档, s 表示编写索引。与往常一样,请参阅手册页以获取更多信息。


I have a question: How to compile a static library in linux with gcc, i.e. I need to compile my source code into a file named out.a. Is it sufficient to simply compile with the command gcc -o out.a out.c? I'm not quite familiar with gcc, hope anyone can give me a hand.

解决方案

See Creating a shared and static library with the gnu compiler [gcc]

gcc -c -o out.o out.c

-c means to create an intermediary object file, rather than an executable.

ar rcs libout.a out.o

This creates the static library. r means to insert with replacement, c means to create a new archive, and s means to write an index. As always, see the man page for more info.

这篇关于如何在Linux中编译静态库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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