[SERVER-11879] Using Windows mongoclient.dll, statics have duplicate storage Created: 27/Nov/13  Updated: 11/Jul/16  Resolved: 14/Jan/14

Status: Closed
Project: Core Server
Component/s: Internal Client
Affects Version/s: None
Fix Version/s: 2.5.5

Type: Bug Priority: Major - P3
Reporter: Eric Milkie Assignee: Mark Benvenuto
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-3364 The C++ Driver compiled as shared lib... Closed
Gantt Dependency
Related
related to CXX-81 On Windows, MONGO_API functions shoul... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

Build mongoclient.lib/.dll.
Build simple_client_demo.cpp, link against mongoclient.lib. Run the program and you will crash in the constructor for DBClientBase.

Participants:

 Description   

It appears that if you link against mongoclient.dll in your project and then execute code that uses a static variable that's declared in the header but has storage reserved in the C++ driver, it may crash. The compiler seems to be allocating storage space for the static variable in the local application even though it should only be using the storage in the DLL.



 Comments   
Comment by Eric Milkie [ 02/Dec/13 ]

I confirmed in the docs. You must use dllimport (or link with a .DEF file for importing, but then you must also change your code to reference all data from the DLL by one further level of indirection).

Comment by Eric Milkie [ 27/Nov/13 ]

This appears to be due to the linker not resolving the static symbols from the dll and the application together at link time.
I seem to have fixed the problem by labelling the static as __declspec(dllimport) in my application, which forces the linker to use the external symbol from the DLL.

Generated at Thu Feb 08 03:26:59 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.