Skip to main content
GameDev.net gamedev.net
🔒 Locked

Conditional linking against already compiled library

Started by fizzlesticks May 8, 2013 at 6:37 AM 1 replies 1.7k views
Original Post
fizzlesticks
fizzlesticks

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.

Squared'D
Squared'D
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.