gcc链接对象文件和库——有什么区别?

时间:2022-05-18 19:28:16

Let's say that there is this command:

假设有这样一个命令:

g++ main.o somefile.o -lc -o main

What is the difference between linking object file somefile.o and linking library libc.a?

链接对象文件somefile有什么区别?o和链接库libc.a?

1 个解决方案

#1


2  

Files ending in ".a" are archive files. They essentially contain a set of ".o"s. Therefore, assuming "libc.a" contains "c1.o", "c2.o" and "c3.o", your command is essentially equivalent to unarchiving "libc.a", then invoking:

在“文件结束。一个“归档文件。它们实际上包含了一组“。o”因此,假设“libc。“包含”c1。o”、“c2。o”和“c3。o“你的命令基本上相当于unarchiving”libc。“,然后调用:

g++ main.o somefile.o c1.o c2.o c3.o -o main

Note that, the objects contained in the ".a" are only included if required, i.e., if at least one of their symbols is referenced by another ".o".

注意,“”中包含的对象。只有在有需要时才会包括“a”,即,如果其中至少一个符号被另一个“.o”引用。

#1


2  

Files ending in ".a" are archive files. They essentially contain a set of ".o"s. Therefore, assuming "libc.a" contains "c1.o", "c2.o" and "c3.o", your command is essentially equivalent to unarchiving "libc.a", then invoking:

在“文件结束。一个“归档文件。它们实际上包含了一组“。o”因此,假设“libc。“包含”c1。o”、“c2。o”和“c3。o“你的命令基本上相当于unarchiving”libc。“,然后调用:

g++ main.o somefile.o c1.o c2.o c3.o -o main

Note that, the objects contained in the ".a" are only included if required, i.e., if at least one of their symbols is referenced by another ".o".

注意,“”中包含的对象。只有在有需要时才会包括“a”,即,如果其中至少一个符号被另一个“.o”引用。