Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS: -std=c++17 requires -mmacosx-version-min=10.14 #44

Closed
jbarlow83 opened this issue Jul 16, 2019 · 2 comments · Fixed by #60
Closed

macOS: -std=c++17 requires -mmacosx-version-min=10.14 #44

jbarlow83 opened this issue Jul 16, 2019 · 2 comments · Fixed by #60

Comments

@jbarlow83
Copy link
Contributor

On macOS, it is not possible to compile with -std=c++17 unless -mmacosx-version-min=10.14. macOS 10.14 is Mojave, the latest version.

It would be best to select -std=c++14 on macOS since it is far more compatible with older versions. Alternately, perhaps something can be fixed in pybind11.h to improve compatibility.

If macOS version is -mmacosx-version-min=10.7, error messages like:

pybind11/pybind11.h:1011:9: error: call to unavailable function 'operator delete': introduced in macOS 10.12
        ::operator delete(p, s);
        ^~~~~~~~~~~~~~~~~

If macOS 10.12 (or 10.13) is selected, as suggested, errors (perhaps unintended) still appear:

pybind11/pybind11.h:1009:9: error: no matching function for call to 'operator delete'
        ::operator delete(p, s, std::align_val_t(a));
        ^~~~~~~~~~~~~~~~~
@NathanBWaters
Copy link

If you have this problem, simply change line 59 in setup.py from:
flags = ['-std=c++17', '-std=c++14', '-std=c++11']
to
flags = ['-std=c++14', '-std=c++11']

Thanks @jbarlow83!

@jagerman
Copy link
Member

jagerman commented Oct 23, 2020

Leaving a note here for posterity:

Having dealt with this recently on another project, there is a fair amount of C++17 that you can get away with under -mmacosx-version-min=10.12; all the core language features are fine, but the things that you can't use (at least that I ran into) are all related to stl exceptions:

  • std::optional or std::variant calls that can throw an exception. (So for instance opt.value() is not allowed, but *opt, opt.has_value(), and opt.value_or(x) are all okay).
  • std::variant - similar to optional: std::holds_alternative<T>(var) is fine, var.get_if<T>(&var) is fine, but var.get<T>() is not allowed.
  • std::filesystem - just don't go near it, I think even with 10.14. (https://github.com/gulrak/filesystem is a great drop-in alternative).
  • std::any - not useful at all when targeting anything older than 10.14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants