Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
338 views
in Technique[技术] by (71.8m points)

c++ - Is there a way to interleave static library and dependent dll compilation (MSVC)?

When compiling multiple libraries with MSVC, the compilation process can execute in parallel for each library.

On the other hand, If I have a dll that link together a handful of static libraries, the dll compilation process must wait until all libraries finish their compilation. At least with the workflow I'm currently using.

I know of 2 possible options to specify this type of link dependency with MSVC:

  1. Add the libraries as references in the dll project.
  2. link the libraries manually either via Poperty Pages -> Input -> Additional Dependencies or pragma statement such as #pragma comment(lib, "mylib.lib").

When using option 1, Visual C++ waits until all the libraries are compiled before it initiates the dll compilation. In my view this is a waste since these are only link time dependencies.

When using the second option, I am not sure that Visual C++ will wait until the dependencies compilation is complete before attempting to link them.

So is it possible to specify that a static library dependency is a link time dependency only and interleave static libraries and dependent dll compilation?

question from:https://stackoverflow.com/questions/65908261/is-there-a-way-to-interleave-static-library-and-dependent-dll-compilation-msvc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Unless you have edited the library's source code, MSVC doesn't compile it (again). But if you have edited it, then obviously you will have to one way or the other (well if you want the features to be in the build). If you edit just the dependent, unless your not talking about circular dependencies, the dependencies wont be recompiled.

When using option 1, Visual C++ waits until all the libraries are compiled before it initiates the dll compilation. In my view this is a waste since these are only link time dependencies.

Yes, you have to build its dependencies before compiling the dependent. What if you have something in the dependent which is something you added recently, after the prior build? You'll have to compile the dependency again right?..

When using the second option, I am not sure that Visual C++ will wait until the dependencies compilation is complete before attempting to link them.

Nope Visual Studio doesn't check if the library exists before compiling it. But then, you have to make sure that the dependencies are compiled before the dependent. Yet again, if you have something new in the dependency, you'll have to compile it.

So is it possible to specify that a static library dependency is a link time dependency only and interleave static libraries and dependent dll compilation?

That's how static libraries work. Libraries are linked at link time, not compile time. The way Visual Studio builds the dependencies is that they maintain a dependency graph. When compiling, it checks if a library needs to be recompiled and if not, leave it.

MSVC also doesn't compile .obj files which aren't changed. So if you want to speed up build time, move (movable) header definitions to source files so that specific source file will be recompiled, rather than all the included source files (the source files which include the header file).

The bottom line is, if your working with a lot of libraries, or even one big library, all the edited sources will be recompiled. Multithreading the build is the only way to speed up compilation. Or you could invest in a dedicated machine to compile it for you (server or something).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...