macOS: -std=c++17 requires -mmacosx-version-min=10.14
jbarlow83 opened this issue · 2 comments
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));
^~~~~~~~~~~~~~~~~
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!
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::optionalorstd::variantcalls that can throw an exception. (So for instanceopt.value()is not allowed, but*opt,opt.has_value(), andopt.value_or(x)are all okay).std::variant- similar tooptional:std::holds_alternative<T>(var)is fine,var.get_if<T>(&var)is fine, butvar.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.