在开发C#的CoreCLR Profiling API相关的程序,需要给一个C#程序写崩溃时记录StackTrace的东西。

Linux编译上遇到了问题,报错如下:

error: /usr/include/c++/14/bits/ranges_base.h:858:27: error: no matching function for call to ‘move()’
  858 |           __it = std::move(__bound);
      |                  ~~~~~~~~~^~~~~~~~~
In file included from /usr/include/c++/14/bits/atomic_base.h:39,
                 from /usr/include/c++/14/atomic:50,
                 from src/CorProfiler.h:3:
/usr/include/c++/14/bits/move.h:126:5: note: candidate: ‘template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)’
  126 |     move(_Tp&& __t) noexcept
      |     ^~~~
/usr/include/c++/14/bits/move.h:126:5: note:   candidate expects 1 argument, 0 provided
In file included from /usr/include/c++/14/bits/specfun.h:43,
                 from /usr/include/c++/14/cmath:3898,
                 from /usr/include/c++/14/math.h:36,
                 from vendor/runtime/src/coreclr/pal/inc/pal.h:44,
                 from vendor/runtime/src/coreclr/pal/inc/rt/palrt.h:121,
                 from vendor/runtime/src/coreclr/pal/inc/rt/rpc.h:15,
                 from vendor/runtime/src/coreclr/pal/inc/rt/objidl.h:12,
  > in src/CorProfiler.cpp

可以看到 std::move() 提示无参数,而这一行是 std::move(__bound)

说明 __bound 被宏定义替换了。

进入CoreCLR项目搜索,可以看到 specstrings.h 相关的头文件定义了 __bound ,而这个头文件在pal目录下,

pal,即 Platform Abstraction Layer,是CoreCLR里用来做平台兼容的东西

可以发现另一个头文件 specstrings_undef.h 里面undef了所有他定义的东西,

所以我们在报错的文件里最后引入这个头文件即可。