.o和.lo文件之间的差异

时间:2021-07-29 02:37:53

What is the difference between .a .o and .lo file in C?

.o和.lo文件在C中的区别是什么?

3 个解决方案

#1


28  

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

”。lo' file是一个库对象,它可以被构建到一个共享库中。o' 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使用它来确定在共享库中可以构建什么对象文件

#2


51  

Difference Between .o, .a, .lo and .so.

Executive Summary

  • .o is typically a non-PIC object file emitted by the compiler (before linker stage) When linked with an exe, the code will be included in the executable -- we bind at link time.
  • .o通常是由编译器(在链接器阶段之前)发出的非pic对象文件,当链接到exe时,代码将被包含在可执行文件中——我们在链接时绑定。
  • .a is typically an archive library containing one or more .o files [non-PIC]. When linked with an exe, the particular "*.o" files in the archive will be inserted into the executable.
  • .a通常是一个包含一个或多个.o文件的存档库[非pic]。当与exe连接时,特殊的“*”。存档中的文件将被插入到可执行文件中。
  • .lo is generally a "library object" that contains PIC code whether manually compiled with gcc -fPIC or using libtool.
  • lo通常是一个“库对象”,它包含PIC代码,无论是用gcc -fPIC手工编译的,还是使用libtool编译的。
  • .so files are "shared object" files. They contains PIC objects.
  • 所以文件是“共享对象”文件。他们包含图片对象。

Note:

注意:

  • If you need static executables then use ".o" and ".a" files.
  • 如果您需要静态可执行文件,那么使用“。o“和”。一个“文件。
  • If you need/want dynamic executables the bind with libraries at run time, use .lo and .so files.
  • 如果您需要/想要动态的可执行文件,请在运行时与库绑定,使用.lo和so文件。

Introduction

While I like the answers above, they do not cover the .a/archive library form. So here I will address all three with a bonus of adding in a .so library format, as well. Also, in the vein of stackexchange, I will use more text in case links get broken (note that I did not need reference links for this one).

虽然我喜欢上面的答案,但它们不包括。a/archive library form。因此,我将在这里对这三种方法进行处理,并添加一个额外的库格式。另外,在stackexchange的静脉中,我将使用更多的文本,以防链接被破坏(注意,我不需要这个链接的参考链接)。

Filetype .o

When compiling a .o file is an object file containing the compiler emitted object code for the target platform. To create a .o file:

在编译一个.o文件时,它是一个包含编译器为目标平台发出的目标代码的对象文件。创建.o文件:

gcc -c filename.c     <==== creates filename.o

Note that this example did not create Position Independent Code (PIC). We consider this an object for possible inclusion in a static library or executable. That is, when we link an executable with a .o file, the code in the .o file is inserted into the executable --- it is bound at build time, not at run time. That means the executable can be redistributed without including the .o file. Caveat: it is convention that the .o file is considered non-PIC. We typically name PIC object files with a .lo extension.

注意,这个示例没有创建位置独立代码(PIC)。我们认为这个对象可以包含在静态库或可执行文件中。也就是说,当我们将可执行文件与.o文件链接时,.o文件中的代码被插入到可执行文件中——它在构建时绑定,而不是在运行时绑定。这意味着可以重新分发可执行文件,而不包括.o文件。注意:.o文件被认为是非pic的。我们通常将PIC对象文件命名为.lo扩展名。

Filetype .a

The .a file type is an "archive" library. It contains one or more .o files and it is typically used to for creating static executable files.

一个文件类型是一个“存档”库。它包含一个或多个.o文件,通常用于创建静态可执行文件。

We use the ar command to manipulate archive libraries. Below in an example that (1) creates an archive library from .o files then (2) lists the contents of one.

我们使用ar命令来操作存档库。下面的示例(1)从.o文件创建一个归档库,然后(2)列出其中一个的内容。

Create the Library

创建库

$ ls *.o
a.o  b.o  c.o                 <=== the files going in the archive

$ ar q libmyStuff.a *.o       <=== put *.o files in an archive (or new one)
ar: creating libmyStuff.a    

$ ls *.a                      <=== just show the library created
libmyStuff.a

Display the Contents of an Archive Library

显示存档库的内容。

$ ar t libmyStuff.a
a.o
b.o
c.o

Filetype .lo

The use of .lo is a convention that is often used for position independent object files. In the current directory the libtool compile command creates both a .lo file and a .o file, one with PIC code and one without PIC code. See the output below:

lo的使用是一种约定,通常用于定位独立的对象文件。在当前目录中,libtool compile命令创建一个.lo文件和一个.o文件,一个带有PIC代码,另一个没有PIC代码。请参见下面的输出:

$ libtool compile gcc -c a.c
libtool: compile:  gcc -c a.c  -fPIC -DPIC -o .libs/a.o  <== PIC code
libtool: compile:  gcc -c a.c -o a.o >/dev/null 2>&1     <== Not-PIC code

$ ls a.lo a.o
a.lo  a.o       <=== a.lo contains the PIC code.

Also note that the .libs subdirectory was created with a.o in it. This file is PIC code, despite the name. Libtool moved this file to the current directory and changed the extension to .lo.

还要注意,.libs子目录是用a创建的。o。此文件是PIC代码,尽管名称是。Libtool将这个文件移动到当前目录,并将扩展名改为.lo。

You can always manually create .lo files simply by using the PIC option(s) to gcc when you compile. Move the resulting .o files to .lo extension.

您可以通过在编译时使用PIC选项来手动创建.lo文件。将结果的.o文件移动到.lo扩展名。

Filetype .so

By convention .so implies a "shared object" library file. We put PIC object files into shared libraries. In contract to .o and .a files, when we link with .so files the code is not included in the resulting compiled file. That is we use run time binding (as in the .lo case). There is more than one form of runtime binding, but we won't go into that here.

根据约定,意味着“共享对象”库文件。我们将PIC对象文件放入共享库中。在与。o和一个文件的合同中,当我们链接到这个文件时,该文件的代码不包含在最终的编译文件中。即我们使用运行时绑定(如.lo情况)。有不止一种形式的运行时绑定,但是这里我们不深入讨论。

#3


4  

The .lo file is a library object, which may be built into a shared library, and the .o file is a standard object file. More info: How to install and use libtool shared library (.lo files)?

lo文件是一个库对象,它可以被构建到一个共享库中,而.o文件是一个标准的对象文件。更多信息:如何安装和使用libtool共享库(。lo文件)?

#1


28  

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

”。lo' file是一个库对象,它可以被构建到一个共享库中。o' 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使用它来确定在共享库中可以构建什么对象文件

#2


51  

Difference Between .o, .a, .lo and .so.

Executive Summary

  • .o is typically a non-PIC object file emitted by the compiler (before linker stage) When linked with an exe, the code will be included in the executable -- we bind at link time.
  • .o通常是由编译器(在链接器阶段之前)发出的非pic对象文件,当链接到exe时,代码将被包含在可执行文件中——我们在链接时绑定。
  • .a is typically an archive library containing one or more .o files [non-PIC]. When linked with an exe, the particular "*.o" files in the archive will be inserted into the executable.
  • .a通常是一个包含一个或多个.o文件的存档库[非pic]。当与exe连接时,特殊的“*”。存档中的文件将被插入到可执行文件中。
  • .lo is generally a "library object" that contains PIC code whether manually compiled with gcc -fPIC or using libtool.
  • lo通常是一个“库对象”,它包含PIC代码,无论是用gcc -fPIC手工编译的,还是使用libtool编译的。
  • .so files are "shared object" files. They contains PIC objects.
  • 所以文件是“共享对象”文件。他们包含图片对象。

Note:

注意:

  • If you need static executables then use ".o" and ".a" files.
  • 如果您需要静态可执行文件,那么使用“。o“和”。一个“文件。
  • If you need/want dynamic executables the bind with libraries at run time, use .lo and .so files.
  • 如果您需要/想要动态的可执行文件,请在运行时与库绑定,使用.lo和so文件。

Introduction

While I like the answers above, they do not cover the .a/archive library form. So here I will address all three with a bonus of adding in a .so library format, as well. Also, in the vein of stackexchange, I will use more text in case links get broken (note that I did not need reference links for this one).

虽然我喜欢上面的答案,但它们不包括。a/archive library form。因此,我将在这里对这三种方法进行处理,并添加一个额外的库格式。另外,在stackexchange的静脉中,我将使用更多的文本,以防链接被破坏(注意,我不需要这个链接的参考链接)。

Filetype .o

When compiling a .o file is an object file containing the compiler emitted object code for the target platform. To create a .o file:

在编译一个.o文件时,它是一个包含编译器为目标平台发出的目标代码的对象文件。创建.o文件:

gcc -c filename.c     <==== creates filename.o

Note that this example did not create Position Independent Code (PIC). We consider this an object for possible inclusion in a static library or executable. That is, when we link an executable with a .o file, the code in the .o file is inserted into the executable --- it is bound at build time, not at run time. That means the executable can be redistributed without including the .o file. Caveat: it is convention that the .o file is considered non-PIC. We typically name PIC object files with a .lo extension.

注意,这个示例没有创建位置独立代码(PIC)。我们认为这个对象可以包含在静态库或可执行文件中。也就是说,当我们将可执行文件与.o文件链接时,.o文件中的代码被插入到可执行文件中——它在构建时绑定,而不是在运行时绑定。这意味着可以重新分发可执行文件,而不包括.o文件。注意:.o文件被认为是非pic的。我们通常将PIC对象文件命名为.lo扩展名。

Filetype .a

The .a file type is an "archive" library. It contains one or more .o files and it is typically used to for creating static executable files.

一个文件类型是一个“存档”库。它包含一个或多个.o文件,通常用于创建静态可执行文件。

We use the ar command to manipulate archive libraries. Below in an example that (1) creates an archive library from .o files then (2) lists the contents of one.

我们使用ar命令来操作存档库。下面的示例(1)从.o文件创建一个归档库,然后(2)列出其中一个的内容。

Create the Library

创建库

$ ls *.o
a.o  b.o  c.o                 <=== the files going in the archive

$ ar q libmyStuff.a *.o       <=== put *.o files in an archive (or new one)
ar: creating libmyStuff.a    

$ ls *.a                      <=== just show the library created
libmyStuff.a

Display the Contents of an Archive Library

显示存档库的内容。

$ ar t libmyStuff.a
a.o
b.o
c.o

Filetype .lo

The use of .lo is a convention that is often used for position independent object files. In the current directory the libtool compile command creates both a .lo file and a .o file, one with PIC code and one without PIC code. See the output below:

lo的使用是一种约定,通常用于定位独立的对象文件。在当前目录中,libtool compile命令创建一个.lo文件和一个.o文件,一个带有PIC代码,另一个没有PIC代码。请参见下面的输出:

$ libtool compile gcc -c a.c
libtool: compile:  gcc -c a.c  -fPIC -DPIC -o .libs/a.o  <== PIC code
libtool: compile:  gcc -c a.c -o a.o >/dev/null 2>&1     <== Not-PIC code

$ ls a.lo a.o
a.lo  a.o       <=== a.lo contains the PIC code.

Also note that the .libs subdirectory was created with a.o in it. This file is PIC code, despite the name. Libtool moved this file to the current directory and changed the extension to .lo.

还要注意,.libs子目录是用a创建的。o。此文件是PIC代码,尽管名称是。Libtool将这个文件移动到当前目录,并将扩展名改为.lo。

You can always manually create .lo files simply by using the PIC option(s) to gcc when you compile. Move the resulting .o files to .lo extension.

您可以通过在编译时使用PIC选项来手动创建.lo文件。将结果的.o文件移动到.lo扩展名。

Filetype .so

By convention .so implies a "shared object" library file. We put PIC object files into shared libraries. In contract to .o and .a files, when we link with .so files the code is not included in the resulting compiled file. That is we use run time binding (as in the .lo case). There is more than one form of runtime binding, but we won't go into that here.

根据约定,意味着“共享对象”库文件。我们将PIC对象文件放入共享库中。在与。o和一个文件的合同中,当我们链接到这个文件时,该文件的代码不包含在最终的编译文件中。即我们使用运行时绑定(如.lo情况)。有不止一种形式的运行时绑定,但是这里我们不深入讨论。

#3


4  

The .lo file is a library object, which may be built into a shared library, and the .o file is a standard object file. More info: How to install and use libtool shared library (.lo files)?

lo文件是一个库对象,它可以被构建到一个共享库中,而.o文件是一个标准的对象文件。更多信息:如何安装和使用libtool共享库(。lo文件)?