diff --git a/brian2/codegen/cpp_prefs.py b/brian2/codegen/cpp_prefs.py index 653dd777b..8045ee01d 100644 --- a/brian2/codegen/cpp_prefs.py +++ b/brian2/codegen/cpp_prefs.py @@ -17,9 +17,13 @@ import subprocess import sys import tempfile -from distutils.ccompiler import get_default_compiler -from setuptools import msvc +try: + from setuptools.msvc import msvc14_get_vc_env as _get_vc_env +except ImportError: # Setuptools 0.74.0 removed this function + from distutils._msvccompiler import _get_vc_env + +from distutils.ccompiler import get_default_compiler from brian2.core.preferences import BrianPreference, prefs from brian2.utils.filetools import ensure_directory @@ -352,7 +356,7 @@ def get_msvc_env(): # Search for MSVC environment if not already cached if _msvc_env is None: try: - _msvc_env = msvc.msvc14_get_vc_env(arch_name) + _msvc_env = _get_vc_env(arch_name) except distutils.errors.DistutilsPlatformError: raise OSError( "Cannot find Microsoft Visual Studio, You " diff --git a/brian2/devices/cpp_standalone/device.py b/brian2/devices/cpp_standalone/device.py index 7cb100b98..a4050a512 100644 --- a/brian2/devices/cpp_standalone/device.py +++ b/brian2/devices/cpp_standalone/device.py @@ -1174,12 +1174,7 @@ def compile_source(self, directory, compiler, debug, clean): self.timers["compile"]["make"] = time.time() - start_time if x != 0: - if os.path.exists("winmake.log"): - with open("winmake.log") as f: - print(f.read()) - error_message = ( - "Project compilation failed (error code: %u)." % x - ) + error_message = f"Project compilation failed (error code: {x}), consider having a look at 'winmake.log'." if not clean: error_message += ( " Consider running with " @@ -1559,10 +1554,20 @@ def build( libraries = self.libraries + prefs["codegen.cpp.libraries"] + codeobj_libraries compiler_obj = ccompiler.new_compiler(compiler=compiler) + + # Distutils does not use the shell, so it does not need to quote filenames/paths + # Since we include the compiler flags in the makefile, we need to quote them + include_dirs = [f'"{include_dir}"' for include_dir in include_dirs] + library_dirs = [f'"{library_dir}"' for library_dir in library_dirs] + runtime_library_dirs = [ + f'"{runtime_dir}"' for runtime_dir in runtime_library_dirs + ] + compiler_flags = ( ccompiler.gen_preprocess_options(define_macros, include_dirs) + extra_compile_args ) + linker_flags = ( ccompiler.gen_lib_options( compiler_obj,