4

I have a C++ dll which I will call Dll A where I have used:

#include <mutex>

Dll As properties are set to "No Common Language Runtime Support" and it builds successfully.

I have another Dll B which includes DLL A in its references. Dll Bs properties are set to: "Common Language Runtime Support (/clr)" as it includes C++/CLI code.

When I build DLL B I get the error: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\mutex(8): fatal error C1189: #error : <mutex> is not supported when compiling with /clr or /clr:pure.

I know that I cannot include in a CLR supported DLL but is there a way I can get around this problem of referencing a dll that does include it?

Daniel Trebbien
  • 38,421
  • 18
  • 121
  • 193
Harry Boy
  • 4,159
  • 17
  • 71
  • 122
  • 2
    It is illegal to use in managed code, the CLR does not provide the guarantee that a managed thread runs on a dedicated operating system thread. Two threads can technically share the same OS thread, making the mutex fail miserably. In practice, that's quite unlikely to happen, there are no known CLR hosts that implement this feature. No guarantee that there are unknown ones of course. The only way to sail around the compile error is to wrap the native code in a C++ source file that's compiled without /clr in effect so your C++/CLI code never sees the mutex. – Hans Passant Oct 27 '14 at 11:36
  • But my whole DLL is compiled without /clr in effect. – Harry Boy Oct 27 '14 at 12:15
  • 1
    Doesn't have anything to do with the DLL, its .h file matters. If client code is not in fact suppose to use the mutex then it needs to be refactored so the implementation details are not so visible. Your snippet doesn't help us help you of course. – Hans Passant Oct 27 '14 at 12:18

0 Answers0