PDA

View Full Version : Clanlib and MongoDB



lampcord
10-06-2012, 05:29 PM
Has anyone made Clanlib project that uses the MongoDB C++ client?

I've been struggling to get it to compile. Running into some sort of header clash between the two libs.

Just wondering if anyone else has tried this or knows a work around.

Or alternatives to mongo for indexable non SQL data stores.

sphair
10-06-2012, 06:25 PM
What is the error you get?

lampcord
10-07-2012, 12:01 AM
What is the error you get?

Sorry, should have posted it with my Q. Not sure what I was thinking.

I'm getting this:

1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\ws2def.h(91): warning C4005: 'AF_IPX' : macro redefinition
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winsock.h(460) : see previous definition of 'AF_IPX'
...


followed by the same error for about 200 variables. Not sure where the references to winsock.h or ws2def.h are coming from but it looks like I need to get rid of one.

RootKernel
10-08-2012, 12:42 PM
Sorry, should have posted it with my Q. Not sure what I was thinking.

I'm getting this:

1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\ws2def.h(91): warning C4005: 'AF_IPX' : macro redefinition
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winsock.h(460) : see previous definition of 'AF_IPX'
...


followed by the same error for about 200 variables. Not sure where the references to winsock.h or ws2def.h are coming from but it looks like I need to get rid of one.

Maybe try to read that stuff : http://stackoverflow.com/questions/1372480/c-redefinition-header-files


41 down vote


This problem is caused when including <windows.h> before <winsock2.h>. Try arrange your include list that <windows.h> is included after <winsock2.h> or define _WINSOCKAPI_ first:

#define _WINSOCKAPI_ // stops windows.h including winsock.h
#include <windows.h>
// ...
#include "MyClass.h" // Which includes <winsock2.h>

lampcord
10-08-2012, 01:27 PM
Maybe try to read that stuff : http://stackoverflow.com/questions/1372480/c-redefinition-header-files

Thanks, good idea. The problem is, the references aren't in any of my code, they are in the library source and I don't want to muck around with that.

I figured out a solution though. I made a dll called DBProxy.dll that has all of the MongoDB references along with some data classes that are shared with my main program to exchange data with it.

All of the conversion to/from BSON and all communication with the MongoDB server take place in the dll so my main program is unburdened with any knowledge about how the data is stored. This has the added benefit that I could switch out MongoDB for another DB or even do serverless storage on my own and I would only have to change the dll. My main program would be unaffected.

This has been tested and it works.