C语言下“.lo”和“.o”的区别

正文

作为一个多年的C程序员,反复接触到后缀为lo的文件,其实一直没有太搞明白(其实是没有太理会),这次做一个总结。

参考这里

The ‘.lo’ file is a library object, which may be built into a shared library, and the ‘.o’ file is a standard object file

The .lo file is the libtool object, which Libtool uses to determine what object file may be built into a shared library

这里说明,.lo文件是libtool生成的文件,被libtool用来生成共享库的;而.o 文件是标准的目标文件。

Shared libraries, however, may only be built from position-independent code (PIC). So, special flags must be passed to the compiler to tell it to generate PIC rather than the standard position-dependent code.

Since this is a library implementation detail, libtool hides the complexity of PIC compiler flags by using separate library object files (which end in ‘.lo’ instead of ‘.o’). On systems without shared libraries (or without special PIC compiler flags), these library object files are identical to “standard” object files.

这里说明,原来的共享库是编自PIC(position-independent code,位置无关)的代码,这是一个实现的细节,libtool隐藏了PIC的flag的复杂性,而采用了分离的库对象文件,以“.lo”代替“.o”结尾。在不需要共享库的系统上,这些库文件等同于标准的目标文件(即.o文件)。

参考

https://stackoverflow.com/questions/5895649/difference-between-a-o-and-lo-file
http://www.delorie.com/gnu/docs/libtool/libtool_8.html

posted on 2018-09-04 10:28  chaiyu2002  阅读(979)  评论(0编辑  收藏  举报

导航