Pedro Ferreira
Pedro Ferreira

Reputation: 860

C1189 #error: <mutex> is not supported when compiling with /clr or /clr:pure

I have a C++ library with managed C++ classes and unmanaged C++ classes, so the library is compiled with /clr support. I need to make some thread safe locking on the unmanaged side but if I include I have the compiler error:

C1189 #error: <mutex> is not supported when compiling with /clr or /clr:pure

How can I work around this? Spent a couple of hours searching but only found very old information. Using Visual Studio 2017 and C++11 language standard.

Upvotes: 1

Views: 2071

Answers (1)

dxiv
dxiv

Reputation: 17638

A mixed-mode project can include both unmanaged C++ and managed C++/CLI code. Since <mutex> "is not supported when compiling with /clr" the code that requires it needs to be moved into a separate .cpp file set to compile without /clr. That can be done by adding a new .cpp file to the project, then changing the Property Pages / Configuration Properties / C/C++ / General / Common Language RunTime Support setting from /clr to none for that particular .cpp file (not for the entire project).

  • The code must be moved to a separate file set to compile without /clr in its entirety. Just putting the code inside a #pragma unmanaged block in a file compiled with /clr will not work.

  • If the project uses precompiled headers, the new file must be set to not use the precompiled header, since that one should not be shared between objects built with vs. without /clr.

Upvotes: 1

Related Questions