2

TL;DR

Is it possible to compile Boost.Regex 1.76 in Header Only Mode (non BOOST_REGEX_CXX03 mode) with a C++/CLI i.e. /clr i.e. _MANAGED project?


We have been using Boost.Regex for years in our regular Visual C++ projects. A very few of our projects are compiled with Common Language Runtime Support (/clr) which enables C++/CLI, (and for these we always linked in the boost regex library statically). We always pre-built the boost regex DLL and static lib and then linked these from MSVC.

Now, with Boost 1.76 Boost.Regex newly is header only, unless compiling in C++03 mode.

( Version 1.76.0 ) ...

Regex:

  • Regex is now header only except in C++03 mode
  • Support for C++03 is now deprecated.
  • ...

However, our C++/CLI project will -- through the boost config magic -- automatically select to build Boost.Regex in the C++03 == BOOST_REGEX_CXX03 mode!

  • Our current MSVC is Visual Studio 19.7.6, _MSC_FULL_VER 192729112

Since no longer having to pre-build any Boost.Regex binaries would be quite handy, we're currently looking into whether we can get the C++/CLI project to compile in the non BOOST_REGEX_CXX03 mode:

  • Does anybody know how through the magic of boost/config the macro BOOST_REGEX_CXX03 is selected for a C++ _MANAGED project? (I currently suspect _CPPLIB_VER, but I'm not even sure what version that is.)
  • Can we switch this? ->

Is it possible to compile Boost.Regex 1.76 in Header Only Mode with a C++/CLI i.e. /clr i.e. _MANAGED project?

Martin Ba
  • 37,187
  • 33
  • 183
  • 337

1 Answers1

2

To answer the question quickly: No it is not possible to compile Boost.Regex in C++11 mode, that is non C++03 mode with the /clr flag on.

The reason BOOST_REGEX_CXX03 gets selected under /clr is that boost\regex\config.hpp will select it if any of ... BOOST_NO_CXX11_HDR_MUTEX ... BOOST_NO_CXX11_HDR_ATOMIC ... are set, and these are set under /clr because C++/CLI only supports C++03, or rather it supports all of C++03 whereas e.g. std::mutex is not supported in C++/CLI.

As others have written:

It is not supported because the std::mutex implementation uses GetCurrentThreadId(). That's a winapi function that is not supposed to be use in managed code since it might be running on a custom CLR host that doesn't use threads to implement threading.

This is the good kind of problem to have, it shows that you are building your code wrong. Your native C++ is being compiled with /clr in effect. Which works rather too well, all C++03 compliant code can be compiled to MSIL ....

So, IFF you need Boost.regex in a translation unit what is compiled /clr, you must use the C++03 mode.

As for the OP problem: Should check whether the given VC++ project that uses C++/CLI really needs to compile all files with /clr on, or maybe the translation units that actually use Boost.Regex are native C++ anyway and could be compiled without /clr and then just linked together with the C++/CLI object files.

Martin Ba
  • 37,187
  • 33
  • 183
  • 337