[CDRIVER-2054] Windows static build is broken in 1.5.0 Created: 06/Feb/17 Updated: 03/May/17 Resolved: 08/Mar/17 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | None |
| Affects Version/s: | 1.5.0 |
| Fix Version/s: | 1.7.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Rustam Abdullaev | Assignee: | A. Jesse Jiryu Davis |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||||||
| Issue Links: |
|
||||||||||||
| Epic Link: | convenient-static | ||||||||||||
| Description |
|
As of libmongoc 1.5.0, attempting to link applications against the static build of the driver will fail with the error that symbols like "__imp_bson_iter_init" and "__imp_mongoc_read_prefs_new" cannot be resolved. Original description:
|
| Comments |
| Comment by levuphuong [ 23/Mar/17 ] | ||||||
|
Hi I pull new source code and change my project win32 to x64 platform which is same with mongoc platform build tool on windows. Thanks so much. | ||||||
| Comment by Githook User [ 21/Mar/17 ] | ||||||
|
Author: {u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}Message: | ||||||
| Comment by Githook User [ 21/Mar/17 ] | ||||||
|
Author: {u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}Message: We'd used BSON_EXPORT, but that doesn't work now because it was updated | ||||||
| Comment by levuphuong [ 20/Mar/17 ] | ||||||
|
I make sure mongoc_static-1.0.lib added already. I added libs with config VC ++
I also try to create sample .lib and then add to my project. it worked fine. i have problem "_imp_mongoc" when
The problem is "_imp_mongoc". I think "_imp_bson", "_imp_mongoc" and "_mongoc" also relate to prefix in "bson-macros.h" file. Thanks. | ||||||
| Comment by Rustam Abdullaev [ 19/Mar/17 ] | ||||||
|
This will not fix "unresolved external symbol _mongoc_init". You probably forgot to link with mongoc_static-1.0.lib. This particular issue is limited to __imp_bson_ related errors. Once libbson is bumped and BSON_STATIC is added to static builds, __imp_bson_ related errors should go away. | ||||||
| Comment by levuphuong [ 09/Mar/17 ] | ||||||
|
I am sorry but i still get error. | ||||||
| Comment by Githook User [ 06/Mar/17 ] | ||||||
|
Author: {u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}Message: | ||||||
| Comment by A. Jesse Jiryu Davis [ 02/Mar/17 ] | ||||||
|
I'm going to submit a libbson fix to for code review. Then:
| ||||||
| Comment by levuphuong [ 02/Mar/17 ] | ||||||
|
Hi @Rustam Abdullaev Can you share me the way hack to use static library C on Windows? | ||||||
| Comment by Hannes Magnusson [ 15/Feb/17 ] | ||||||
|
Thank you for the detailed analysis. You are correct that we do not have any tests for static builds in evergreen at the moment. | ||||||
| Comment by J Rassi [ 15/Feb/17 ] | ||||||
|
I can reproduce rustyx's issue with their attached project. Building on Rustam's investigation, the cause of this issue appears to be a libmongoc regression introduced in 1.5.0 by
The C++ driver team never noticed this issue, as we currently have no build integration for static libmongoc at all, Windows or otherwise (I'll be filing a ticket for this shortly, and linking it here). However, four of our users noticed this in the past week or two (users Simon and Romain at https://groups.google.com/forum/#!topic/mongodb-user/iUaqAMScXMM, user Pia_who_love_Sia at http://stackoverflow.com/questions/42003413/mongocxx-in-windows-lnk2001-unresolved-external-symbol-imp-mongoc-read-prefs, and Rustam, on this ticket) when they upgraded to mongocxx 3.1.x, which requires libmongoc 1.5.0+. These users are manually listing mongoc-static-1.0.lib / bson-static-1.0.lib as project library dependencies in Visual Studio. Does the C driver Evergreen integration attempt to compile the examples against a static build of the driver? If not, then we should certainly file a ticket for that as well, as I believe that would have also caught this issue. Rustam reports above that the hack of defining BSON_COMPILATION while building mongocxx appears to work around this issue (by forcing BSON_API to expand to __declspec(dllexport), so the symbol names match), but I'm not sure if there are any other adverse affects of doing this. Linking against the dynamic build of the C driver also avoids this issue, but I would guess that that isn't feasible for all users. Thank you so much for your original report, your reproducible case, and your patience, rustyx! | ||||||
| Comment by Rustam Abdullaev [ 08/Feb/17 ] | ||||||
|
Please try using it. bson-static-1.0.lib is fine, but it can't be used. As the header declares everything __declspec(dllimport) none of entries in bson-static-1.0.lib can be found as everything gets the __imp__ prefix. | ||||||
| Comment by A. Jesse Jiryu Davis [ 08/Feb/17 ] | ||||||
|
I don't think this is a libbson build bug. Our CMakeLists.txt defines BSON_COMPILATION: https://github.com/mongodb/libbson/blob/1.6.0/CMakeLists.txt#L202 I've rebuilt the driver just now with VS 2015 according to the standard build instructions:
This shows that "bson_iter_init" is defined. There's no "__imp__bson_iter_init". | ||||||
| Comment by David Golden [ 07/Feb/17 ] | ||||||
|
Thank you. We'll take a look. | ||||||
| Comment by Rustam Abdullaev [ 07/Feb/17 ] | ||||||
|
Added test project | ||||||
| Comment by David Golden [ 07/Feb/17 ] | ||||||
|
Rustam, I'd like to try to replicate this locally and diagnose it. Could you please send/attach/post the build-equivalent of an SSCCE? I.e. The exact step by step commands you're executing to get the failure you described and the exact step by step commands you're executing to get the success? Thank you! | ||||||
| Comment by Rustam Abdullaev [ 06/Feb/17 ] | ||||||
|
Don't think it's a versioning issue because adding "/D BSON_COMPILATION" to CMAKE_CXX_FLAGS for libbsoncxx fixes the issue. I tried libmongoc 1.6.0 and master with libmongocxx (release/stable). | ||||||
| Comment by David Golden [ 06/Feb/17 ] | ||||||
|
Hi, Rustam. Which specific version of libmongoc do you have installed? 3.1.0 requires libmongoc 1.5 or later, so you might be missing those symbols because you have an old version. See the mongoc releases page to get updated source. | ||||||
| Comment by Rustam Abdullaev [ 06/Feb/17 ] | ||||||
|
Seems to be caused by this code in libbson / bson-macros.h:
I think that BSON_COMPILATION was defined before, and that's why it kind of worked (at least I don't know what happens with functions declared dllexport in a static lib). But obviously that is not the solution. There should be a way to specify BSON_STATIC and #define BSON_API as empty. |