Sign in to follow this  
gunning

Visual C++: Sharing Code Across Projects

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
@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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this