Repository: qutip/qutip

Issue:
macOS 10.14 compilation problem
It seems the new macOS can not compile QuTiP, it can not find `<complex>`. The headers do present in `/usr/include` (however it required a header package installation on the new macOS)



Discussion:
Is it the case so, I was just about to upgrade to Mojave. Is it the issue with IDLE or Notebooks?
If the QuTiP is already installed then there is no problem after the update, it works.
I will submit a patch to the installer later today.  Basically you need to add `'-mmacosx-version-min=10.9'` to the `_compiler_flags` and `extra_link_args`.

Resolving patch:
diff --git a/qutip/cy/pyxbuilder.py b/qutip/cy/pyxbuilder.py
--- a/qutip/cy/pyxbuilder.py
+++ b/qutip/cy/pyxbuilder.py
@@ -44,6 +44,9 @@ def new_get_distutils_extension(modname, pyxfilename, language_level=None):
         extension_mod.extra_compile_args = ['/w', '/O1']
     else:
         extension_mod.extra_compile_args = ['-w', '-O1']
+        if sys.platform == 'darwin':
+            extension_mod.extra_compile_args.append('-mmacosx-version-min=10.9')
+            extension_mod.extra_link_args = ['-mmacosx-version-min=10.9']
     return extension_mod,setup_args
 
 pyximport.pyximport.get_distutils_extension = new_get_distutils_extension
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -150,6 +150,9 @@ def write_version_py(filename='qutip/version.py'):
         'spmath', 'heom', 'math', 'spconvert', 'ptrace', 'testing', 'brtools',
         'brtools_testing', 'br_tensor', 'piqs']
 
+# Extra link args
+_link_flags = []
+
 # If on Win and Python version >= 3.5 and not in MSYS2 (i.e. Visual studio compile)
 if (sys.platform == 'win32' and int(str(sys.version_info[0])+str(sys.version_info[1])) >= 35
     and os.environ.get('MSYSTEM') is None):
@@ -157,6 +160,12 @@ def write_version_py(filename='qutip/version.py'):
 # Everything else
 else:
     _compiler_flags = ['-w', '-O3', '-march=native', '-funroll-loops']
+    if sys.platform == 'darwin':
+        # These are needed for compiling on OSX 10.14+
+        _compiler_flags.append('-mmacosx-version-min=10.9')
+        _link_flags.append('-mmacosx-version-min=10.9')
+
+
 
 EXT_MODULES =[]
 # Add Cython files from qutip/cy
@@ -165,7 +174,7 @@ def write_version_py(filename='qutip/version.py'):
             sources = ['qutip/cy/'+ext+'.pyx', 'qutip/cy/src/zspmv.cpp'],
             include_dirs = [np.get_include()],
             extra_compile_args=_compiler_flags,
-            extra_link_args=[],
+            extra_link_args=_link_flags,
             language='c++')
     EXT_MODULES.append(_mod)
 
@@ -174,7 +183,7 @@ def write_version_py(filename='qutip/version.py'):
             sources = ['qutip/control/cy_grape.pyx'],
             include_dirs = [np.get_include()],
             extra_compile_args=_compiler_flags,
-            extra_link_args=[],
+            extra_link_args=_link_flags,
             language='c++')
 EXT_MODULES.append(_mod)
 
@@ -194,7 +203,7 @@ def write_version_py(filename='qutip/version.py'):
                        'qutip/cy/openmp/src/zspmv_openmp.cpp'],
             include_dirs = [np.get_include()],
             extra_compile_args=_compiler_flags+omp_flags,
-            extra_link_args=omp_args,
+            extra_link_args=omp_args+_link_flags,
             language='c++')
     EXT_MODULES.append(_mod)
     # Add benchmark pyx
@@ -202,7 +211,7 @@ def write_version_py(filename='qutip/version.py'):
             sources = ['qutip/cy/openmp/benchmark.pyx'],
             include_dirs = [np.get_include()],
             extra_compile_args=_compiler_flags,
-            extra_link_args=[],
+            extra_link_args=_link_flags,
             language='c++')
     EXT_MODULES.append(_mod)
     
@@ -211,7 +220,7 @@ def write_version_py(filename='qutip/version.py'):
             sources = ['qutip/cy/openmp/br_omp.pyx'],
             include_dirs = [np.get_include()],
             extra_compile_args=_compiler_flags,
-            extra_link_args=[],
+            extra_link_args=_link_flags,
             language='c++')
     EXT_MODULES.append(_mod)
     
@@ -220,7 +229,7 @@ def write_version_py(filename='qutip/version.py'):
             sources = ['qutip/cy/openmp/omp_sparse_utils.pyx'],
             include_dirs = [np.get_include()],
             extra_compile_args=_compiler_flags+omp_flags,
-            extra_link_args=omp_args,
+            extra_link_args=omp_args+_link_flags,
             language='c++')
     EXT_MODULES.append(_mod)
 


Test patch: