views:

88

answers:

3

Hi,

I have built up a number of common modules which I have been hitherto keeping in one directory and referencing from the project directories that need them.

I was wondering if there was a better way of doing this ?

Both the common modules and the code using them are written in C++.

+3  A: 

I would suggest creating a static library and linking with it. It's much simpler than a DLL, you don't have to worry about versioning, and all-around you work with them just as you would with your common modules.

EDIT: Basically, a static library is a collection of object files. If you're working with Visual Studio, you can create a static library project (or change the output type of your project) which will create a .lib file that you can link in your application. If you're using GCC, you can use "ar" to create the library file from a bunch of .o files, and again link it to your application.

Tal Pressman
I like that idea, can you provide more information or links to an explaination?
Konrad
A: 

I like to put them in a dll so that the size of my executable becomes less.

Naveen
+1 The downvote was ridiculous. Countered.
Sahasranaman MS
+1  A: 

Managing and improving your private set of tools is an important thing for a programmer. I personally always go for the "as quick'n easy as possible" approach.

The faster they are linked and included into my work the sooner I feel "at home". I am even sometimes throwing all orderlines away and chuck them into default library and include paths, and whoopie, there they are, at your service. (Wouldn't really recommend that of course, but it is quick'n easy)

I don't know why you use dlls, since a normal lib would cause fewer headaches to include.

Tip: Make a seperate project out of them. Have them in a central logical location. (Maybe myWorkspace/MyLibs) Since your toolset will likely grow/change/improve with every project you are working on, I sometimes set up my working environment to be able to swiftly switch over, add something and then go back to the original project. In this case it is useful to include it as a project dependency in your IDE that can be built automatically and then relinked. This is trivial with almost all IDE's.

A different problem however are employers. They are usually wary about things you carry over into their projects. Especially if you want to close the source to them. But this is a story for another question ;)

AndreasT
Good point about employers - however this is just for my own personal projects.
Konrad