I'm currently trying to figure out whether it is possible for two different native Visual-C++ projects (that have exactly the same compiler settings) to share their intermediate files (obj, pch, ...)
An example should help:
This is a normal setup:
PROJECTS \ P1 \ p1.vcproj; p1.cpp; ...
\ Release_Intermediate_Dir \ p1.obj
\ tool1.obj
\ P2 \ p2.vcproj; p2.cpp; ...
\ Release_Intermediate_Dir \ p2.obj
\ tool1.obj
\ COMMON \ tool1.cpp; ...
What about this setup:
PROJECTS \ P1 \ p1.vcproj (uses: p1.cpp; p1_main.cpp)
\ p1_test.vcproj (uses: p1.cpp; p1_test.cpp)
\ Release_Intermediate_Dir \ p1.obj (used by both projects p1 and test)
\ tool1.obj
\ p1_main.obj (only p1.vcproj)
\ p1_test.obj (only p1_test.vcproj
\ COMMON \ tool1.cpp; ...
Can I use the same intermediate folder for two C++ projects, thereby sharing the obj
files directly?
Or will I always need to have an additional static lib project? (As far as I understand, a static lib is just a container for obj
files.)
Why would I want to do this? Look at this blog post: Writing Unit Tests in Visual Studio for Native C++.
It uses a static lib for the sole purpose of having two different executables (main functions, if you will). (Forget about the managed/CLI stuff.) This means having 3 projects in your solution (having to maintain three projects), when you really only want two projects that share the same code with the same compilation settings but use a different main/startup rigging.