[CXX-266] Driver won't compile on Windows with cl.exe (MSVC compiler) Created: 29/Jun/14  Updated: 08/Jul/14  Resolved: 07/Jul/14

Status: Closed
Project: C++ Driver
Component/s: Build
Affects Version/s: legacy-0.10.0
Fix Version/s: legacy-0.11.0

Type: Bug Priority: Major - P3
Reporter: Kamil N Assignee: Tyler Brock
Resolution: Done Votes: 0
Labels: legacy-cxx
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File error.txt     Text File sock_h_error.txt    

 Description   

Not sure if anyone tried compiling it with Microsoft Visual Studio C++ (I use most recent 2013 build), but it won't compile due to a problem with certain windows headers.

I tracked it down to two cases - one where mongo/platform/process_id.h fails because certain file that includes it doesn't also include "mongo/platform/basic.h" which in turn includes required windows headers (it lacks definition of DWORD). Another problem is with net/sock.h which, on the other hand, misses definition of sockaddr.

It seems that only certain .cpp files include "mongo/platform/basic.h" and its not enough. I solved it temporarily by just including this file in both, process_id.h and sock.h. Not sure what the intentions were, but either its basic and should be included in every file, or its selectively included in files that need it, but then it seems quite a lot of files were omitted - almost every file compiled throws an error because it either lacks DWORD def or sockaddr.

I attached compiler error.



 Comments   
Comment by Tyler Brock [ 07/Jul/14 ]

https://github.com/mongodb/mongo-cxx-driver/pull/117

Comment by Tyler Brock [ 07/Jul/14 ]

Kamil, would you mind confirming that the driver compiles now for you using the current legacy branch of the driver?

Comment by Githook User [ 07/Jul/14 ]

Author:

{u'username': u'TylerBrock', u'name': u'Tyler Brock', u'email': u'tyler.brock@gmail.com'}

Message: CXX-266 ensure basic.h is included where needed
Branch: legacy
https://github.com/mongodb/mongo-cxx-driver/commit/6b6d83a3bb7b7c32dd135056d1468f9c2507d034

Comment by Andrew Morrow (Inactive) [ 02/Jul/14 ]

noizex See this file for a correctly formatted inclusion of basic.h: https://github.com/mongodb/mongo-cxx-driver/blob/legacy/src/mongo/client/bulk_operation_builder.cpp

Comment by Andrew Morrow (Inactive) [ 02/Jul/14 ]

Hi @Kamil N -

Yes, adding basic.h as the first include as necessary is the correct resolution. Are you willing to put together a pull request containing your fixes? If so, please read our contributors guide and sign the contributors agreement if you have not already done so.

Thanks,
Andrew

Comment by Kamil N [ 01/Jul/14 ]

Ok, I attached sock.h errors file. I just copied 3 cases there, but the same error persists in other files. I wasn't sure what would be the best solution so I just did dirty hack with including basic.h inside sock.h file instead of including it in each of .cpp files, but there is at least 10 of them.

If you can confirm that thats what should be done (just putting basic.h as first include in each affected file) then its easily solved, and I encountered no other errors.

May be that older versions of MSVC somehow append winsock.h / windows.h by default, or supply these headers in other way, and on MSVC2013 its just not there until its included by user.

Comment by Andrew Morrow (Inactive) [ 01/Jul/14 ]

Thanks. The rule is that it is always safe to add basic.h to .cpp files (always as the first include, followed by a blank line, then system headers, then mongo headers), and it should never be added to .h files.

Comment by Kamil N [ 01/Jul/14 ]

Sure, I will post them once I get back home. I think the sock.h issue was more severe in terms of number of files affected, I think without copy&pasting "#include basic.h" to each .cpp file, there was an error. I stopped after few files and just added this include to the sock.h itself if I remember well. I will confirm it later when I post error logs.

Comment by Andrew Morrow (Inactive) [ 01/Jul/14 ]

noizex

RE the process_id issue: the issue is that oid.cpp needs to include basic.h. Can you post the error that you get re sock.h?

Thanks,
Andrew

Comment by Andrew Morrow (Inactive) [ 01/Jul/14 ]

Hi noizex

Thanks for the bug report. We do currently do automated builds with MSVC, but I think with 2010.

I think you are correct that process_id.h needs basic.h.

Also, it looks like process_id.h is currently staged to the $PREFIX/include directory, despite no other public headers including it.

We will try to get to this in the next release, or if you want to put together a pull request we will work with you to get it merged.

Thanks,
Andrew

Generated at Wed Feb 07 21:58:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.