Skip to content

Commit d06f228

Browse files
committed
BLD: Verify the ability to compile C++ sources before initiating the build
1 parent 2513620 commit d06f228

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

numpy/core/setup.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -672,16 +672,29 @@ def get_mathlib_info(*args):
672672
# but we cannot use add_installed_pkg_config here either, so we only
673673
# update the substitution dictionary during npymath build
674674
config_cmd = config.get_config_cmd()
675-
676675
# Check that the toolchain works, to fail early if it doesn't
677676
# (avoid late errors with MATHLIB which are confusing if the
678677
# compiler does not work).
679-
st = config_cmd.try_link('int main(void) { return 0;}')
680-
if not st:
681-
# rerun the failing command in verbose mode
682-
config_cmd.compiler.verbose = True
683-
config_cmd.try_link('int main(void) { return 0;}')
684-
raise RuntimeError("Broken toolchain: cannot link a simple C program")
678+
for lang, test_code, note in (
679+
('c', 'int main(void) { return 0;}', ''),
680+
('c++', (
681+
'int main(void)'
682+
'{ auto x = 0.0; return static_cast<int>(x); }'
683+
), (
684+
'note: A compiler with support for C++11 language '
685+
'features is required.'
686+
)
687+
),
688+
):
689+
st = config_cmd.try_link(test_code, lang=lang)
690+
if not st:
691+
# rerun the failing command in verbose mode
692+
config_cmd.compiler.verbose = True
693+
config_cmd.try_link(test_code, lang=lang)
694+
raise RuntimeError(
695+
f"Broken toolchain: cannot link a simple {lang.upper()} "
696+
f"program. {note}"
697+
)
685698
mlibs = check_mathlib(config_cmd)
686699

687700
posix_mlib = ' '.join(['-l%s' % l for l in mlibs])

0 commit comments

Comments
 (0)