我正在尝试编译在使用Ubuntu 18.04和Windows 10编译时没有问题的程序。但是,当我尝试在OSX High Sierra上编译该程序时,出现错误,它们仅与boost相关。
这是一个示例:
#include <boost/process.hpp>
#include <iostream>
int main()
{
std::cout << "This is a test." << std::endl;
}
然后我尝试使用g++
和clang
来编译程序,如下所示:
g++ -std=c++11 test.cpp -lpthread
然后我得到这个大错误:
In file included from test.cpp:1:
In file included from /usr/local/include/boost/process.hpp:24:
In file included from /usr/local/include/boost/process/async_system.hpp:22:
In file included from /usr/local/include/boost/process/child.hpp:21:
In file included from /usr/local/include/boost/process/detail/child_decl.hpp:30:
/usr/local/include/boost/process/detail/posix/wait_for_exit.hpp:60:7: error: expected unqualified-id
::sigemptyset(&sigset);
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/signal.h:125:26: note: expanded from macro 'sigemptyset'
#define sigemptyset(set) (*(set) = 0, 0)
^
In file included from test.cpp:1:
In file included from /usr/local/include/boost/process.hpp:24:
In file included from /usr/local/include/boost/process/async_system.hpp:22:
In file included from /usr/local/include/boost/process/child.hpp:21:
In file included from /usr/local/include/boost/process/detail/child_decl.hpp:30:
/usr/local/include/boost/process/detail/posix/wait_for_exit.hpp:61:7: error: expected unqualified-id
::sigaddset(&sigset, SIGCHLD);
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/signal.h:122:31: note: expanded from macro 'sigaddset'
#define sigaddset(set, signo) (*(set) |= __sigbits(signo), 0)
^
In file included from test.cpp:1:
In file included from /usr/local/include/boost/process.hpp:24:
In file included from /usr/local/include/boost/process/async_system.hpp:22:
In file included from /usr/local/include/boost/process/child.hpp:21:
In file included from /usr/local/include/boost/process/detail/child_decl.hpp:30:
/usr/local/include/boost/process/detail/posix/wait_for_exit.hpp:87:26: error: no member named 'sigtimedwait' in the global namespace
auto ret_sig = ::sigtimedwait(&sigset, nullptr, &ts);
~~^
In file included from test.cpp:1:
In file included from /usr/local/include/boost/process.hpp:25:
In file included from /usr/local/include/boost/process/group.hpp:32:
/usr/local/include/boost/process/detail/posix/wait_group.hpp:64:7: error: expected unqualified-id
::sigemptyset(&sigset);
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/signal.h:125:26: note: expanded from macro 'sigemptyset'
#define sigemptyset(set) (*(set) = 0, 0)
^
In file included from test.cpp:1:
In file included from /usr/local/include/boost/process.hpp:25:
In file included from /usr/local/include/boost/process/group.hpp:32:
/usr/local/include/boost/process/detail/posix/wait_group.hpp:65:7: error: expected unqualified-id
::sigaddset(&sigset, SIGCHLD);
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/signal.h:122:31: note: expanded from macro 'sigaddset'
#define sigaddset(set, signo) (*(set) |= __sigbits(signo), 0)
^
In file included from test.cpp:1:
In file included from /usr/local/include/boost/process.hpp:25:
In file included from /usr/local/include/boost/process/group.hpp:32:
/usr/local/include/boost/process/detail/posix/wait_group.hpp:90:17: error: no member named 'sigtimedwait' in the global namespace
ret = ::sigtimedwait(&sigset, nullptr, &ts);
~~^
6 errors generated.
我可能会缺少编译器标志,我尝试过-lboost_system
,但是给出了相同的确切错误。如果该特定的库与OSX不兼容,那么我将尝试查找解决方法,但是该库已经嵌入在我当前使用的代码中。
是否有已知的修复方法?
答案 0 :(得分:2)
您是正确的。 Full Source有关详细信息,请单击错误报告的链接。
错误报告中提供了一种变通方法,使其可以在MacOS上进行编译:
事实证明,MacOS不是唯一定义
using System.Security.Principal; [Authorize(AuthenticationSchemes = IISServerDefaults.AuthenticationScheme)] public ActionResult SomeAction() { var windowsIdentity = HttpContext.User.Identity as WindowsIdentity; var windowsUser = new WindowsPrincipal(windowsIdentity); var role = "[MY-COMPUTER-NAME || AD GROUP NAME]\\[GROUP NAME]"; var inInRole = windowsUser.IsInRole(role); // todo: if not allowed write code to handle it return View(); }
,//AuthorizationHandler<T> protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, RoleRequirement requirement) { if (!(context.User.Identity is WindowsIdentity windowsIdentity)) return Task.CompletedTask; var windowsUser = new WindowsPrincipal(windowsIdentity); try { var hasRole = windowsUser?.IsInRole(requirement.GroupName) ?? false; if (hasRole) context.Succeed(requirement); } catch (Exception ex) { logger.LogError(ex, "Unable to check groups the user belongs too"); } return Task.CompletedTask; } //IAuthorizationRequirement public class RoleRequirement : IAuthorizationRequirement { public RoleRequirement(string groupName) { GroupName = groupName; } /// <summary> /// The Windows / AD Group Name that is allowed to call the OMS API /// </summary> public string GroupName { get; } } //action protected with the policy [Authorize("Super User Role")] public IActionResult Contact() { return View(); } //startup.cs public void ConfigureServices(IServiceCollection services) { //pull group name from the config var securityOptions = Configuration.GetSection("Security").Get<SecurityOptions>(); services.AddAuthentication(IISDefaults.AuthenticationScheme); services.AddAuthorization(options => { options.AddPolicy("Super User Role", policy => { policy.Requirements.Add(new RoleRequirement(securityOptions.AllowedGroup)); policy.AddAuthenticationSchemes("Windows"); }); }); services.AddSingleton<IAuthorizationHandler, RoleHandler>(); // ... }
的平台。这很容易解决,因为您只需删除sigemptyset
限定词即可。至于sigaddset
,这并不是在所有平台上都常见。奇怪的是,从该限定符中删除::
限定符后,即可编译代码。我猜想模板永远不会实例化,因此该方法不存在不会导致我们出现问题。我可以提供补丁,但无非就是从这三个标识符中删除
sigtimedwait
。
包含了一个全面的补丁程序As of 1.69.0 Boost.Process is broken on MacOS.。请注意,如果您选择在代码中包含Flint的补丁,则Flint是MIT许可的