How to use the same obj files in different projects in the same solution

血红的双手。 提交于 2020-01-25 00:31:05

问题


I have a solution that contains several projects. Some of these projects share source files. I have set up my project tree so that the projects that share source files are together. My problem is that when I do a clean and build the shared source files get re-compiled for every project, not just the first one that uses them. The result is that the initial build takes longer than it should and I have to build more than once to get all of the dependencies satisfied (re-links are necessary.) The project is a port from a gcc project that uses a series of make files to perform the build. The make files do not repeat the compiles. Is there any way to handle the above situation so that the dependencies are satisfied in Visual Studio as one would expect? Is the problem due to a dependency between the source file and the .idb and .pdb files?

Update: What I really need is a way to tell VS to perform a re-link on the same obj files with different DLL and LIB names. I can get this to work by including .obj files in the re-link projects but haven't been able to figure out how to create debug/release versions. In the sections of the project files the $(IntDir) does not seem to get parsed. So...

In project1

file1.c file2.c file3.c link into dll1.dll,dll1.lib

then in project 2 the object files from the project1 get linked again only this time into dll2.dll,dll2.lib

project3 same thing. etc.

I posted this on an MS forum also and as yet have not received an answer.


回答1:


If you can reorganise the code to do this, build the shared .obj files into a library project, then you can link with that library from the dependent projects.

That's the only "clean" way I can think of to solve the problem - anything else I can think of is likely to involve "fighting" or "tricking" visual studio, which is usually a bad idea.



来源:https://stackoverflow.com/questions/2603278/how-to-use-the-same-obj-files-in-different-projects-in-the-same-solution

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