在UNIX中创建一个项目,从Makefile以静态/动态库 [英] Creating a project, from Makefile to static/dynamic libraries in UNIX
问题描述
家伙,你会形容对C ++的积木的几件事情,在UNIX。
Guys, would you describe a few things about c++ building blocks, on unix.
我要创建一个防静电库和动态库(的.so)链接的应用程序。
I want to create an application that links against static libs and dynamic libs (.so).
问题1: 如何创建一个使用静态库的gcc / g ++的我如何反对我的应用程序的链接的
问题2: 如何在Makefile指定它,链接到的静态和动态库,假设这两个库都头文件的
摘要:我一直在使用多年的makefile和库,由别人写的。因此,每一个我修改它的时候,我只是剪切和粘贴周围的事物,没有真正理解它。现在,我想倒在地上,了解建筑/连接/创建Makfile深入的过程。
Summary: I have been using makefiles and libraries for years, written by someone else. Thus every time I modified it, I simply cut-and-pasted things around, without really understanding it. Now I want to get down to the ground and understand the building/linking/Creating Makfile process in-depth.
的什么是好书描述贴心细节这些概念?的
感谢
推荐答案
静态库通常归档的使用 AR
命令。一旦你建立所有目标文件(preferably与海湾合作委员会 -fPIC
开关),你可以运行 AR
像这样:
Static libraries are usually archived with the ar
command. Once you build all of the object files (preferably with the -fPIC
switch on GCC), you can run ar
like so:
ar -rs archivename.a list.o of.o objects.o
的人
页描述的选项。
动态库是用 -shared
开关置于 GCC
或 LD <通常建立/ code>,并用
的.so
扩展的输出文件名。
Dynamic libraries are built usually with the -shared
switch to gcc
or ld
and the output file name with a .so
extension.
自动工具处理这与的libtool
程序。我不熟悉其使用。
Autotools handles this with the libtool
program. I'm not familiar with its use.
链接到这些库可以通过列出与 -l </ code>(ELL)开关库(如
-lx $做到无论C $ C>链接到
libX.so
)或直接使用绝对路径指定它们(如添加 /usr/lib/libX.so
你的命令)。静态库通过指定链接 -static
在 -l </ code>或适当的绝对路径
.A
归档。
Linking against these libraries can be done either by listing the libraries with the -l
(ell) switch (such as -lX
to link to libX.so
) or by specifying them directly with absolute paths (such as adding /usr/lib/libX.so
to your command). Static libraries are linked by specifying -static
before -l
or the appropriate absolute path to the .a
archive.
这篇关于在UNIX中创建一个项目,从Makefile以静态/动态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!