环境

boost

Boost 1.72

Win

报错:

2>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\fileapi.h(53,1): error C2116: 'boost::interprocess::winapi::CreateDirectoryA': function parameter lists do not match between declarations
2>D:\software\boost_1_72_0\boost\interprocess\detail\win32_api.hpp(945): message : see declaration of 'boost::interprocess::winapi::CreateDirectoryA'

解决方案:

boost_1_72_0\boost\interprocess\detail\win32_api.hpp添加#define BOOST_USE_WINDOWS_H,
如下图:

后续

加了前文所述一行后,又遇到 boost_1_72_0\boost\asio\detail\socket_types.hpp这个文件报出的fatal error C1189: #error: WinSock.h has already been included报错。

解决方法

添加 #include <winsock2.h>,如下图

新报错

按照前述操作之后,又有新报错:
11>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared\ws2def.h(240,25): error C2011: 'sockaddr': 'struct' type redefinition

解决方案:

boost_1_72_0\boost\interprocess\detail\win32_api.hpp也加 #include <winsock2.h>

至此,大功告成,编译成功。

重要参考文章

https://github.com/boostorg/process/issues/161
https://stackoverflow.com/questions/9750344/boostasio-winsock-and-winsock-2-compatibility-issue
https://stackoverflow.com/questions/1372480/c-redefinition-header-files-winsock2-h
https://stackoverflow.com/questions/31434556/error-c2011-sockaddr-struct-type-redefinition-see-declaration-of-sockad