What is the difference between .LIB and .OBJ files? (Visual Studio C++)

坚强是说给别人听的谎言 提交于 2019-12-29 04:30:09

问题


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?

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?


回答1:


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.




回答2:


It seems like the .lib file is like a collection of .obj files. Some people also regard the process,that switch several .obj files to .lib files, as Archive. In that case, the .lib file is a box of .obj file, which could be treated equally by linker.



来源:https://stackoverflow.com/questions/1361071/what-is-the-difference-between-lib-and-obj-files-visual-studio-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!