vc++ .NET sharing source files between projects

Started by
4 comments, last by Nemesis2k2 18 years, 10 months ago
Currently I have two project which use some of the same .cpp and .h files. What is the best way to do this. Currently i just created a solution for the first project, and then i added my second project to that later. So all the source and project files are in one spot. It seems like it might be better if i kept my source in one spot, and my project files in another. And then just set the source location as a search path. Although if the source folder had sub folders, would it search those or would i have to add all those to the source path. Anyway, i really think i need some suggestions on this. How do people handle it.
Advertisement
If both projects are using the SAME headers/source files(Or, a part of it), why not place these source/header files into a seperate project and compile it to a lib file?

That's what I do with my 'framework'. I have a project in which a have a basic set of C++ code. Classes/functions which are shared between projects. I created a static library project, dumped all the files into it and then batch built the thing.

I ended up with the lib files for both debug/release. I then added the folder to the project settings(Include/Lib) and it worked perfect. All you then have to do is go to the linker settings and add <yourlib.lib> to the list of libs to link in.

After that, you can save yourself the hassle from compiling those files(So you'll probably notice a small speed up) and you don't need to add the files to your project.

Toolmaker

maybe i will do that. However, my application also needs to be built on linux, and i don't know how to build a lib on linux.
A static library (.lib) is combined into your executable at compile time. The platform doesn't matter. It's dynamically linked libraries (eg, .dll) that tend to be platform specific.
Uhmn. Library files also must be platform-specific (just like DLLs), as in - compiled for each platform.


Anyway - my personal recomendation is to also have the framework in its own folders and have the project in seperate folders, referencing the framework. However, instead of using a library or dynamicly-linked library, just directly reference the source and headers from your projects.

I find that this is much more flexible, especially if you make a lot of interface changes and/or use templates.

And, if you find you outgrow this method, use Subversion to version, branch and merge your framework between projects.
Quote:Uhmn. Library files also must be platform-specific (just like DLLs), as in - compiled for each platform.

Only if they have platform specific elements, or the architecture of the target platform is different. Corrington_j seemed to think that building a static lib for a linux app was different to building one for a windows app, which I was pointing out it is not. DLL's are a different matter, as you have to load and deal with them differently on various different platforms, and not all platforms have support for them at all. Static libraries are a compile-time concern, and can be used for any program, on any platform, in the exact same way. It's just a matter of recompiling them where nessicary for the correct platform.

This topic is closed to new replies.

Advertisement