Skip to main content
gamedev.net
🔒 Locked

Visual C++: Sharing Code Across Projects

Started by gunning 2 replies 1.9k views
Original Post
gunning
gunning
I need suggestions for how to structure a Visual C++ solution. There are multiple applications and DLLs in the solution, each their own VC++ project, which share many of the same header and source files. I want to be able to edit all these shared files in one place. Ideally, there would be a dummy project that contained them and each project would link to it, but just creating an empty project I fear my pre-compiled headers would cause trouble since each project uses a different one. Maybe the IDE has a name for such a shared code project that I'm not familiar with. Does that make sense? Any ideas from those more experienced than I?
....[size="1"]Brent Gunning
spraff
spraff
Pre-compiled headers shouldn't matter. The shared header files can go anywhere, just add them to your include path. As for shared code files, you can add compiled object files to your link path in much the same way. If you want to *edit* the source for several modules in different solutions all in one place I would argue that you're generally too tightly coupled and you're not designing your modules as properly self-contained units.
Codarki
Codarki
I'm not sure if I understand you correctly. You have several projects (.exe or .dll) in one solution, and same source files are included in them? ie. same .cpp file included in more than one vc project?

If so, answer is to make a static library, and link the library to those projects which want to use it.
gunning
gunning
@spraff

Thanks. The reason I mentioned pre-compiled headers is because in each source file I have

#include "stdafx.h"

to make the compiler happy, but the PCH is different for each project. So I figured that might cause problems... maybe not ...

FYI the project involves passing around common data structures/classes between different DLLs/executables and both ends need to use the same classes.


@Ftn

Thanks also. I think a static library is exactly what I'm looking for. (How did I not think of that? It's been a while...) I was thinking originally to include the shared source files in each project and compile them separately in each, but it makes much more sense to compile them only once and share the static library.
....[size="1"]Brent Gunning

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.