diff --git a/doc/source/user/building.rst b/doc/source/user/building.rst index 22efca4a6f83..01ec65d3b6b3 100644 --- a/doc/source/user/building.rst +++ b/doc/source/user/building.rst @@ -48,6 +48,9 @@ Building NumPy requires the following software installed: Much of NumPy is written in C. You will need a C compiler that complies with the C99 standard. + Part of Numpy is now written in C++. You will also need a C++ compiler that + complies with the C++11 standard. + While a FORTRAN 77 compiler is not necessary for building NumPy, it is needed to run the ``numpy.f2py`` tests. These tests are skipped if the compiler is not auto-detected. diff --git a/numpy/core/setup.py b/numpy/core/setup.py index 136492dd5e86..0bd868c288ba 100644 --- a/numpy/core/setup.py +++ b/numpy/core/setup.py @@ -464,6 +464,8 @@ def configuration(parent_package='',top_path=None): from numpy.distutils.misc_util import Configuration, dot_join from numpy.distutils.system_info import (get_info, blas_opt_info, lapack_opt_info) + from numpy.distutils.ccompiler_opt import NPY_CXX_FLAGS + from numpy.version import release as is_released config = Configuration('core', parent_package, top_path) local_dir = config.local_path @@ -738,11 +740,17 @@ def get_mathlib_info(*args): ): is_cpp = lang == 'c++' if is_cpp: - # this a workround to get rid of invalid c++ flags + # this a workaround to get rid of invalid c++ flags # without doing big changes to config. # c tested first, compiler should be here bk_c = config_cmd.compiler config_cmd.compiler = bk_c.cxx_compiler() + + # Check that Linux compiler actually support the default flags + if hasattr(config_cmd.compiler, 'compiler'): + config_cmd.compiler.compiler.extend(NPY_CXX_FLAGS) + config_cmd.compiler.compiler_so.extend(NPY_CXX_FLAGS) + st = config_cmd.try_link(test_code, lang=lang) if not st: # rerun the failing command in verbose mode @@ -1080,10 +1088,7 @@ def generate_umath_c(ext, build_dir): libraries=['npymath'], extra_objects=svml_objs, extra_info=extra_info, - extra_cxx_compile_args=['-std=c++11', - '-D__STDC_VERSION__=0', - '-fno-exceptions', - '-fno-rtti']) + extra_cxx_compile_args=NPY_CXX_FLAGS) ####################################################################### # umath_tests module # diff --git a/numpy/distutils/ccompiler_opt.py b/numpy/distutils/ccompiler_opt.py index b38e47c13a94..205a8e060f69 100644 --- a/numpy/distutils/ccompiler_opt.py +++ b/numpy/distutils/ccompiler_opt.py @@ -16,6 +16,14 @@ import subprocess import textwrap +# These flags are used to compile any C++ source within Numpy. +# They are chosen to have very few runtime dependencies. +NPY_CXX_FLAGS = [ + '-std=c++11', # Minimal standard version + '-D__STDC_VERSION__=0', # for compatibility with C headers + '-fno-exceptions', # no exception support + '-fno-rtti'] # no runtime type information + class _Config: """An abstract class holds all configurable attributes of `CCompilerOpt`, diff --git a/numpy/linalg/setup.py b/numpy/linalg/setup.py index 94536bb2c055..73c386f1ccbf 100644 --- a/numpy/linalg/setup.py +++ b/numpy/linalg/setup.py @@ -3,6 +3,7 @@ def configuration(parent_package='', top_path=None): from numpy.distutils.misc_util import Configuration + from numpy.distutils.ccompiler_opt import NPY_CXX_FLAGS from numpy.distutils.system_info import get_info, system_info config = Configuration('linalg', parent_package, top_path) @@ -72,6 +73,7 @@ def get_lapack_lite_sources(ext, build_dir): sources=['umath_linalg.c.src', get_lapack_lite_sources], depends=['lapack_lite/f2c.h'], extra_info=lapack_info, + extra_cxx_compile_args=NPY_CXX_FLAGS, libraries=['npymath'], ) config.add_data_files('*.pyi')