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

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

问题描述

我有一个问题:如何在 Linux 中使用 gcc 编译静态库,即我需要将我的源代码编译成一个名为 out.a 的文件.仅使用命令 gcc -o out.a out.c 进行编译就足够了吗?我对gcc不是很熟悉,希望有人能帮我.

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.

推荐答案

参见 Creating带有 gnu 编译器的共享静态库 [gcc]

gcc -c -o out.o out.c

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

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

ar rcs libout.a out.o

这将创建静态库.r 表示插入替换,c 表示创建新存档,s 表示写入索引.与往常一样,请参阅手册页了解更多信息.

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