Growing Libraries between projects

Started by
8 comments, last by Schrompf 11 years, 6 months ago
When I wrote things that are not specific to the very application, and could be useful elsewhere, I’ll often move them to a library.
So far, that library always was part of a workspace (e.g. MSVC workspace) of projects that were related, as an own project.
I would then, despite knowing better, carry that library over to another project, i.e. copy. That means maintenance of several different places, keeping copies of the library in sync when bugs are discovered, or extensions are made, which may become useful for a later stage of older projects.
I knew from the beginning that it would probably be a good idea to have the library as a completely separate project, and only use binaries of it in other projects.
But then… it’s easier to debug everything if the library is part of a project. That’s why I kept it that way.
I can't say I'm really happy that way, though.

How do you do this sort of stuff?
Advertisement
I don't know about other compilers, but Visual Studio can debug binary even if it was built in separate solution as long as debug information is present.

I think it also allows to add external projects to solution without copying, so you'll have only 1 instance of project.
I can only comment on what i have done, but so far(knock on wood) I haven't had too many issues.

My code is broken up into several libraries, most started as a project in one of my original solutions(vs lingo). As it sits now I have 5 or 6 game projects on the go, as well as 6 or 7 different libraries, math, graphics, physics, networking, sound, etc. I'll like never polish any of the game as they are, for the most part I use them to as tech experiments.

When I get some key functionality, like sprite animation, working the way I want in a game project, I create a new version of the library it should reside in or perhaps a new library all together, if it's something I've never encountered, and refactor the changes there.

When I'm working on a game project that does require functionality that exists in a new version of one of the included libs, I'll create a new version of the game project, make any changes necessary to use the new code, and go from there.

This way other game projects which didn't require that functionality can keep on using older versions of the libs, and I can continue to improve or polish these tech demo projects. As an added bonus, I get a growing base of functionality that has been refined and tested in multiple situations, to use in future projects.

While some might say i'm making engines not games, I have fun regardless, and have gained enough knowledge to feel confident enough that these projects could be finished up at some point in time, even if i never get around to it.


How do you do this sort of stuff?


"Add Existing Project" and have both solutions refer to the same shared project.
I've found that a key point here is to distinguish between library code compilation and linking and source revision control. I use the following approach:

- a single GIT repository for all projects.
- a library folder where all shared code go, such as math and low-level graphics stuff and other nice-to-have things.
- use GIT branching and tagging to keep track of latest stable version of each project.
- when library code diverge between projects (as it does!) use GIT to merge the diffs.

This way both the library code and the project code can evolve in a controlled way, so that changes in one project doesn't break code in another project.

openwar - the real-time tactical war-game platform

Without knowledge of one particular vendor's specialized tool, I can tell you that the solution for this problem developed by various system engineers some decades ago was something called a "shared library". The idea was that all of the common code would be maintained in one place, and bug fixes or enhancements would be done once in one place and used everywhere. Security fixes would be distributed for immediate and universal benefit.

On the Micosoft Windows OS a shared library is implemented as a DLL. On Mac OS X it's a framework. On ELF systems it's an SO file.

To be a useful shared library, the library file itself must go in a common (shared) area. That generally has to be a system directory for the runtime file, although there are always methods for using non-system paths. The development files (headers, link libraries if required) can generally be installed in non-system development paths and build configurations adjusted accordingly. the library itself is usually considered a completely separate project, benefits from things like stable versioned releases and regression testing, and can be separately distributed so it can be shared with friends and colleagues.

This is very, very fundamental technology. I suggest you are better off using what has been developed, tuned, and tested by many experts over many years than to come up with your own solution.

Stephen M. Webb
Professional Free Software Developer


This is very, very fundamental technology. I suggest you are better off using what has been developed, tuned, and tested by many experts over many years than to come up with your own solution.


I'm not sure I get your point here... are you against static libraries in general?

But the question isn't about static/dynamic libraries, it's about how to organize your workspace when developing the project and the library in parallell.
?the library itself is usually considered a completely separate project, benefits from things like stable versioned releases and regression testing, and can be separately distributed so it can be shared with friends and colleagues.?



This is one end of the spectrum, and the appropriate approach in some cases where the library project is well defined and reasonably large. I've found myself on the other end, where I first tended to write the same code (e.g vector math) over and over again, and then moved to lots of copy-and-paste over and over again, and finally to GIT. There's no real "library" project in there, no library "team" and definitely no planned work devoted just for library code. There's just a lot of code reuse that's evolving over time. Moving to GIT (or any other good version control system) is the right tool for such an agile approach where you always work on real products and any shared code is generated as a byproduct of the refactoring steps.

openwar - the real-time tactical war-game platform

If you don't like DLL's you can just use the DLL's for development and static link when you're done.

If you use svn you can use svn externals: http://svnbook.red-bean.com/en/1.0/ch07s03.html, to nest repositories within repositories.

So let's say you have 3 projects

/project1
/project2
/project3

And a common module

/module

You use SVN externals to add create:

/project1/module
/project2/module
/project3/module

where all three link to the same folder which is

/module

I'm not sure how SVN externals work with branching though. And since you say you use updated versions for new projects it sounds like you'll need that branching capability.
I say Code! You say Build! Code! Build! Code! Build! Can I get a woop-woop? Woop! Woop!
I found myself in the same situation, reusing my personal libraries in every project I start. And these libraries used to grow along with the project, so I, too, found myself in need to merge the various development steps into the other instances of the framework.

My solution: Subversion "external". I created a separate repository for the framework with all its libraries and their corresponding Visual Studio projects. Then I created a directory in each solution, usually called SourceExt/, and added a subversion property to check out the framework repository into this directory. Then it's just a simple "Add existing project" and maybe adjusting some include paths in the solution. And because of relative paths everywhere any of my team mates can simply pull the whole thing from the subversion repository and build it right away. I even put DirectX, FMod, PhysX and all the other dependencies there. Relative paths go a long way when used correctly.

Of course this is the opposite of what Bregma suggests, for example. But seriously: your project is most probably not important enough to add even more trash to the user's system's library directory. And dynamic linking prevents inlining and Link Time Code Generation, which is the single most important source of performance improvements in any of my projects. You don't want to place your framework in DLLs / SOs or whatever if you can link statically. So my suggestion is: link statically, share the repository.
----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.

This topic is closed to new replies.

Advertisement