Jump to content

  • Log In with Google      Sign In   
  • Create Account

Conditional linking against already compiled library


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 fizzlesticks   Members   -  Reputation: 157

Like
0Likes
Like

Posted 08 May 2013 - 12:37 AM

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, 08 May 2013 - 12:39 AM.


Sponsor:

#2 Squared'D   Members   -  Reputation: 2258

Like
1Likes
Like

Posted 08 May 2013 - 12:49 AM

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.

Learn all about my current projects and watch some of the game development videos that I've made.

Squared Programming Home

New Personal Journal

 


#3 AllEightUp   Moderators   -  Reputation: 4268

Like
0Likes
Like

Posted 08 May 2013 - 03:14 AM

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 AllEightUp, 08 May 2013 - 03:29 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS