@@ -672,16 +672,38 @@ 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+ is_cpp = lang == 'c++'
690+ if is_cpp :
691+ # this a workround to get rid of invalid c++ flags
692+ # without doing big changes to config.
693+ # c tested first, compiler should be here
694+ bk_c = config_cmd .compiler
695+ config_cmd .compiler = bk_c .cxx_compiler ()
696+ st = config_cmd .try_link (test_code , lang = lang )
697+ if not st :
698+ # rerun the failing command in verbose mode
699+ config_cmd .compiler .verbose = True
700+ config_cmd .try_link (test_code , lang = lang )
701+ raise RuntimeError (
702+ f"Broken toolchain: cannot link a simple { lang .upper ()} "
703+ f"program. { note } "
704+ )
705+ if is_cpp :
706+ config_cmd .compiler = bk_c
685707 mlibs = check_mathlib (config_cmd )
686708
687709 posix_mlib = ' ' .join (['-l%s' % l for l in mlibs ])
0 commit comments