Jump to content
  • Advertisement
Sign in to follow this  

[C++] Organise a large or multi-subject library

This topic is 3125 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've lately been working on a GUI library, but since I also included resource management, event handling and other 'general' subjects, I thought I could as well extend the library to be more of a common library with many uses. Mainly for my own development, but it also will be published. So, I currently have a GUI part, a Resources/Data part and a Common part (common stuff the other parts use). I will be extending this likely to networking / math / scripting support / input / 3D etc etc. I just split the library up in 3 parts, which all 3 get linked to the executable. However, this way I create a lot of dependencies and is prone to errors...it's a pain to get the linking done in the right sequence... I then thought, what if I just put it all together again, into one library, but each part is in a different directory and has a different namespace (for example GUI:: or Data:: but not Library::GUI:: or Library::Data::). However, what if I want to have a DLL created (I only use static libs atm) that does not have code for the GUI for example. Would I need to use macro's to filter out code one doesn't need? How do you organize a library that covers multiple subjects? Or anything large(ish)? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Decrius
I just split the library up in 3 parts, which all 3 get linked to the executable. However, this way I create a lot of dependencies and is prone to errors...it's a pain to get the linking done in the right sequence...


That's just the way linking works. As long as the dependencies aren't cylic, you're fine. If the dependencies are cyclic, then you really do have one library (though if you feel like they should be 3, you should work to decouple them).

Quote:

I then thought, what if I just put it all together again, into one library, but each part is in a different directory and has a different namespace (for example GUI:: or Data:: but not Library::GUI:: or Library::Data::).

It's an option, but you may find it harder to keep coupling at bay.

Quote:

However, what if I want to have a DLL created (I only use static libs atm) that does not have code for the GUI for example. Would I need to use macro's to filter out code one doesn't need?


What do you mean? If you don't need a library (any of the symbols inside it), you don't link it.

Quote:

How do you organize a library that covers multiple subjects? Or anything large(ish)?


FWIW, I tend to prefer smaller libraries that do what I tell them, rather than those that provide a framework for me to fill in.

With big "groups" of libraries such as boost or Qt, there's the perception (and sometimes the reality) that you need to download huge swathes of code, even though you'll only use 2% of it. So if it were me, I would at least try to make it easier to use and distribute the libs individually by separating the sources and so on.

Share this post


Link to post
Share on other sites
Quote:
Original post by the_edd
FWIW, I tend to prefer smaller libraries that do what I tell them, rather than those that provide a framework for me to fill in.

With big "groups" of libraries such as boost or Qt, there's the perception (and sometimes the reality) that you need to download huge swathes of code, even though you'll only use 2% of it. So if it were me, I would at least try to make it easier to use and distribute the libs individually by separating the sources and so on.


Yes, I know exactly what you mean. I too dislike those large libraries, although boost is more of a pack of libraries, you can choose each to use.

Good that you open my eyes, hehe, almost made a bulk lib, lol. I will couple the cyclic linkages. Thanks :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Decrius
Yes, I know exactly what you mean. I too dislike those large libraries, although boost is more of a pack of libraries, you can choose each to use.

Good that you open my eyes, hehe, almost made a bulk lib, lol. I will couple the cyclic linkages. Thanks :)


Does this mean you're putting them all in to one big library? I was trying to say that I wouldn't do this! Instead, I would clearly "market" them under the same umbrella but make it clear that they could be used and downloaded individually.

Share this post


Link to post
Share on other sites
Well, I have the Common library which is used by all other parts, and currently the GUI library. I will add networking, math etc libraries. All can be used individually, except for Common, which all libraries depend on.

But yeah, the resources part was a bit blurry...each widget depends on a resource. Be it a texture, a sprite, a font et cetera. So I really removed the cyclic dependencies, makes it possible to use only a certain library instead of the whole.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!