Sailanarmo
Sailanarmo

Reputation: 1181

Are some libraries in Boost 1.69 not compatible with MacOS?

I am trying to compile a program that I have had no issues compiling with Ubuntu 18.04 and Windows 10. However, when I try to compile it on OSX High Sierra I am given errors and they are only related to boost.

This is an example:

#include <boost/process.hpp>
#include <iostream>

int main()
{
  std::cout << "This is a test." << std::endl;
}

I have then tried to compile the program with both g++ and clang like this:

g++ -std=c++11 test.cpp -lpthread

I then get this massive error:

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.

I could be missing a compiler flag, I have tried -lboost_system but that gave the same exact errors. If this specific library is not compatible with OSX then I will try and find a work around, but this library is already embedded in the code that I am currently working with.

Are there any known fixes for this?

Upvotes: 5

Views: 1229

Answers (1)

Cinder Biscuits
Cinder Biscuits

Reputation: 5241

You are correct. As of 1.69.0 Boost.Process is broken on MacOS. For the gritty details, follow the link to the bug report.

There is a workaround given in the bug report to get it compiling on MacOS:

Turns out that MacOS isn't the only platform that defines sigemptyset, sigaddset. That is an easy fix since all you need to do is drop the :: qualifier. As for the sigtimedwait, that too isn't common on all platforms. Strangely, stripping the :: qualifier from that one gets the code to compile. I am guessing that template is never instantiated so the fact the method does not exits isn't causing us problems.

I can supply a patch but it is nothing more than stripping :: from those 3 identifiers.

A comprehensive patch is included in the Flint project. Note that Flint is MIT licensed if you choose to include their patch in your code

Upvotes: 3

Related Questions