.LIB 和 .OBJ 文件有什么区别?(Visual Studio C++)

我知道 .OBJ 是编译一个编译单元的结果,.LIB 是一个静态库,可以从几个 .OBJ 创建,但这种区别似乎只在编译单元的数量上.还有其他区别吗?是相同还是不同的文件格式?

I know .OBJ is the result of compiling a unit of compilation and .LIB is a static library that can be created from several .OBJ, but this difference seems to be only in the number of units of compilation. Is there any other difference? Is it the same or different file format?

当我想知道在两个(或更多).LIB 中定义的相同静态变量是否在链接到最终可执行文件期间被合并时,我遇到了这个问题.对于 .OBJ,变量被合并.但在 .LIB 中是否也一样?

I have come to this question when wondering if the same static variable defined in two (or more) .LIBs is merged or not during linking into the final executable. For .OBJs the variables are merged. But is it the same in .LIBs?

推荐答案

.LIB 文件是与索引连接在一起的 .OBJ 文件的集合.链接器的处理方式也应该没有区别.

A .LIB file is a collection of .OBJ files concatenated together with an index. There should be no difference in how the linker treats either.

相关文章