Recently, the dependency management section of a compilation system is designed. If the dependency closure (all direct and indirect dependencies) of a project has different versions of the same library, we think there is a version conflict here. When we detect a version conflict, we will report a warning message to the user, or report an error to exit directly, ask the user to solve the version conflict first? In fact, both on Windows and Linux, we have mechanisms to ensure that different versions of libraries can be in the sameProgramIn Windows, side-by-side assembly is implemented through manifest and activation context, while in Linux, rpath is set. Therefore, the action of compiling the system should be to report a warning, let the user determine whether the version conflict is a problem or acceptable, and provide a mechanism for the user to suppress this warning-then, generate a side-by-side library for different platforms.
For how to implement the underlying side-by-side, there are three aspects:
- Shared assembly in Windows: for libraries built using VC ++, such as CRT, ATL, MFC, and OpenMP, these libraries correspond to compiler, therefore, different versions of VC ++ will insert different manifest during compilation to indicate where the dependent library comes from. This user basically does not need to do any work.
- Private assembly in Windows: your own library. If you want to side-by-side, you need to provide the corresponding manifest, and the library must be placed under the subdirectory of the application. Microsoft provides the document
- In rpath in Linux, there is a section in binary that allows you to set rpath. When you need to find the library, you will find it from this path.
Here is the first example. Shared assembly in Windows: Source Code address
Foo is a DLL compiled with vs2008, dependent on vscrt90, bar is an EXE, compiled with vs2010, naturally dependent on vscrt100, and it also depends on foo. The project uses premake description to generate the Visual Studio file and compile it with msbuild.
The compilation procedure is as follows:
1. Build foo
* CD foo
* Premake4 vs2008
* "C: \ Program Files (x86) \ Microsoft Visual Studio 9.0 \ common7 \ tools \ vsvars32.bat"
* Msbuild Foo. sln
2. Build bar
* CD bar
* Premake4 vs2010
* "C: \ Program Files (x86) \ Microsoft Visual Studio 10.0 \ common7 \ tools \ vsvars32.bat"
* Msbuild bar. sln
3. Copy Foo. DLL to bar/
Run bar.exe and open procexp to view the process:
We can see that the libraries of vscrt90 and vscrt100 are loaded to the same process at the same time.