Jump to content
  • Advertisement
Sign in to follow this  
fizzlesticks

Conditional linking against already compiled library

This topic is 2049 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

Hello, I'm currently working on a game engine that includes networking using winsock. I compile the engine into a .lib and link to it in my game. However the game does not require networking and I'd like to not be forced to link with winsock for no reason.

 

The only way I can think of doing this is wrap all my net code with something like "#ifdef networking" and compile 2 versions of the engine, 1 with networking and 1 without, which would lead to a huge number of combinations if I want to do that same with other things such as physics or audio. Is there a better way of doing this?

Thanks.

 

p.s. sorry for the horrible title, I had no idea how to word that.

Edited by fizzlesticks

Share this post


Link to post
Share on other sites
Advertisement
Have you considered dividing your engine into two separate projects and then have two separate libraries? You can have one lib file with the core engine stuff and the other lib file with just the networking. Then games that need both should link with both libraries. Otherwise just use the core lib file.

If you use 2 library files, make sure that none of the code in the core library references any of the code in the network lib. If you do, you'l have to include both libraries no matter what.

I do this, and it works very well. I noticed this technique when looking at the Nvidia PhysX code.

Share this post


Link to post
Share on other sites
Guest Hiwas

The separate library approach is your best bet as squared mentions.  I setup the build system in my CMake articles with this specific sort of modular approach in mind, though I did not get into the details of how it is used.  But in the repository for the SIMD math articles, which is moving towards real game work, you can see the usage in action https://code.google.com/p/a8u-tutorial-sources/.  The two testbed applications are very different though they share portions of the codebase.  One is command line and doesn't include any of the graphics related items and the other is a graphical (well currently just a window) testbed using sfml, gl and other things.  The same approach works well with networking, just don't link related libraries unless required.

Edited by Hiwas

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!