From 378ca4b46df9f88dfa359e994acab763b665d2f7 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Tue, 4 Dec 2018 00:06:42 +0100 Subject: [PATCH] Fix OSX build problem --- setup.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 0f4b501a4..501dfe153 100755 --- a/setup.py +++ b/setup.py @@ -7,10 +7,27 @@ import sys import contextlib from distutils.command.build_ext import build_ext from distutils.sysconfig import get_python_inc +import distutils.util from distutils import ccompiler, msvccompiler from setuptools import Extension, setup, find_packages +def is_new_osx(): + '''Check whether we're on OSX >= 10.10''' + name = distutils.util.get_platform() + if sys.platform != 'darwin': + return False + elif name.startswith('macosx-10'): + minor_version = int(name.split('-')[1].split('.')[1]) + if minor_version >= 7: + return True + else: + return False + else: + return False + + + PACKAGE_DATA = {"": ["*.pyx", "*.pxd", "*.txt", "*.tokens"]} @@ -57,8 +74,17 @@ COMPILE_OPTIONS = { LINK_OPTIONS = {"msvc": [], "mingw32": [], "other": []} -# I don't understand this very well yet. See Issue #267 -# Fingers crossed! +if is_new_osx(): + # On Mac, use libc++ because Apple deprecated use of + # libstdc + COMPILE_OPTIONS["other"].append("-stdlib=libc++") + LINK_OPTIONS["other"].append("-lc++") + # g++ (used by unix compiler on mac) links to libstdc++ as a default lib. + # See: https://stackoverflow.com/questions/1653047/avoid-linking-to-libstdc + LINK_OPTIONS["other"].append("-nodefaultlibs") + + + USE_OPENMP_DEFAULT = "0" if sys.platform != "darwin" else None if os.environ.get("USE_OPENMP", USE_OPENMP_DEFAULT) == "1": if sys.platform == "darwin":