Search code examples
cwindowsvisual-c++linker

On Windows MSVC, is it possible to merge some .obj into one .obj? If yes, how should I do that?


For example, there is three object files a.obj b.obj c.obj just compiled out with cl, and it is desired to combine them into one combined.obj.

A comment of an SO question points out that on *nix it's possible to do this kind of thing with ld. However, cl and link all seems only support .exe, .dll and .lib as output.


The whole procedure of what I want to do with the combined object file as follows:

  1. a.obj b.obj c.obj -> combined.obj
  2. combined.obj d.obj e.obj -> executable.exe

My problem is solved. a.obj b.obj c.obj use some variables and functions yet to be linked, and I thought that .lib can't tolerant missing functions since it is a library, but in fact it is OK. I can just merge them into an .lib file:

lib *.obj /OUT:combined.lib

Solution

  • Seems not, but it is convenient to merge them into an .lib:

    lib *.obj /OUT:combined.lib