Author Topic: Having trouble integrating RakNet into a Win32 SDL application (SOLUTION FOUND)  (Read 8825 times)

ViridianGames

  • Not-a-newbie
  • *
  • Posts: 6
  • Karma: 0
    • View Profile
I have a game that I'm developing that has Windows and Linux versions.  Integrating RakNet into the Linux version was a snap; I used the "add all of RakNet's source to the project" method.

But integrating it into the Windows (Win32) version has been unsuccessful so far.  All of the samples in the RakNet project are console applications; none have given me any insight on solving this problem.

I begin by taking my application and adding the RakNet source to it, as well as adding the source location to the Include Folders in the properties.  I also add ws2_32.lib to my library inputs.  This builds.

But as soon as I try to include the basic RakNet include files in one of MY header files, IE:

#include "MessageIdentifiers.h"
#include "RakPeerInterface.h"
#include "RakNetTypes.h"

Just attempting to build again results in build failure with tons of errors.  I'm not actually even making an instance of RakPeerInterface yet; I'm just including those headers.  Here's a sample of the errors I'm getting:

1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(3910) : error C2059: syntax error : '}'
1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2ipdef.h(120) : warning C4005: 'IP_TTL' : macro redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(351) : see previous definition of 'IP_TTL'
1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2tcpip.h(760) : error C2065: 'Filter' : undeclared identifier

Etc, etc, for hundreds of lines.

Any ideas?  I'm eager to get back to, you know, writing my actual game.
« Last Edit: March 13, 2014, 12:17:15 PM by ViridianGames »

ViridianGames

  • Not-a-newbie
  • *
  • Posts: 6
  • Karma: 0
    • View Profile
Re: Having trouble integrating RakNet into a Win32 application
« Reply #1 on: March 07, 2014, 03:33:57 PM »
Still having trouble with this.  I can only assume there's a conflict between RakNet and one of the other libraries I'm using but I can't imagine what it could be.  I'm using SDL, SDL_Image, SDL_Mixer, GLM, GLEW, OpenGL and Boost and that's about it.  Any help would be appreciated.

Anthony

ViridianGames

  • Not-a-newbie
  • *
  • Posts: 6
  • Karma: 0
    • View Profile
Re: Having trouble integrating RakNet into a Win32 application
« Reply #2 on: March 11, 2014, 04:05:43 AM »
Okay, as far as I can tell, it's not possible to include the basic RakNet include files in a header file that is included in multiple other headers later.  No matter what kind of wrapping I use to prevent multiple includes, I always get a steady stream of "redefined object" errors.

This means that as far as I can tell, I can only use RakNet by including it in .cpp files.  Which means I cannot encapsulate RakNet into a a C++ class.

Someone tell me if I'm wrong.  Or hell, just say SOMETHING so I know someone is reading this.

RuiF

  • Not-a-newbie
  • *
  • Posts: 8
  • Karma: 1
    • View Profile
Re: Having trouble integrating RakNet into a Win32 application
« Reply #3 on: March 12, 2014, 07:23:11 AM »
Still having problems with this?
The project I'm working on, uses a mix of static libraries, and even a wxWidgets (win32) application, all using RakNet, and I don't have any problems.
I recall having some issues with headers too, caused by the order and what windows headers I was including.
I can't check at the moment how I've organized my includes, but if you are still having problems, I might be able to take a look later.

Rui

ViridianGames

  • Not-a-newbie
  • *
  • Posts: 6
  • Karma: 0
    • View Profile
Re: Having trouble integrating RakNet into a Win32 application
« Reply #4 on: March 12, 2014, 01:25:41 PM »
Still having problems with this?
The project I'm working on, uses a mix of static libraries, and even a wxWidgets (win32) application, all using RakNet, and I don't have any problems.
I recall having some issues with headers too, caused by the order and what windows headers I was including.
I can't check at the moment how I've organized my includes, but if you are still having problems, I might be able to take a look later.

Rui


Thanks for replying.  The fact that I'm using SDL (which is a cross-platform graphics library that encapsulates the Windows stuff) means I'm not calling any Windows includes directly.  I thought this might be a problem but I know of many games that use SDL and RakNet together successfully.

But I'll start looking in that direction.  Thanks again.

Anthony

ViridianGames

  • Not-a-newbie
  • *
  • Posts: 6
  • Karma: 0
    • View Profile
Re: Having trouble integrating RakNet into a Win32 SDL application
« Reply #5 on: March 13, 2014, 12:17:02 PM »
SOLUTION FOUND.

The problem was hinted at in the FAQ.  It turned out I was having a variation on the "winsock.h included before winsock2.h" problem.  But SDL encapsulates all that stuff, so I wasn't able to solve the problem just by moving headers around.

I finally solved it by adding WIN32_LEAN_AND_MEAN to my preprocessor definitions.  This prevents winsock.h from being loaded at all, which means winsock2.h is free to do its thing.  The result was a clean compile and run.  This was also why it worked perfectly the first time on Linux; Linux doesn't have this problem.

Thanks to RuiF who pointed me in the right direction.

And now back to game programming!

RuiF

  • Not-a-newbie
  • *
  • Posts: 8
  • Karma: 1
    • View Profile
You are welcome.
Good luck with Planitia :)

ViridianGames

  • Not-a-newbie
  • *
  • Posts: 6
  • Karma: 0
    • View Profile
Um...thanks!  I don't recall mentioning Planitia, but yeah, it's the game I'm working on :)

More info here, if anyone cares:

http://www.viridiangames.com/?page_id=13