From a3ceb3c8f9fa3de5d12d24e56fe0bfdc7b89ee8b Mon Sep 17 00:00:00 2001 From: Jakub Streit Date: Thu, 7 Aug 2025 17:04:16 +0200 Subject: [PATCH] Remove "-std=c++11" and "-fvisibility=hidden" if compilet with MSVC --- cppimport/templating.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cppimport/templating.py b/cppimport/templating.py index f479e75..aaa9e20 100644 --- a/cppimport/templating.py +++ b/cppimport/templating.py @@ -65,9 +65,26 @@ def setup_pybind11(cfg): import pybind11 cfg["include_dirs"] += [pybind11.get_include(), pybind11.get_include(True)] + # Prefix with c++11 arg instead of suffix so that if a user specifies c++14 # (or later!) then it won't be overridden. - cfg["compiler_args"] = ["-std=c++11", "-fvisibility=hidden"] + cfg["compiler_args"] + prefix_args = ["-std=c++11", "-fvisibility=hidden"] + # MSVC compiler do not support "-std=c++11" nor "-fvisibility=hidden" + if os.name == "nt": + import sys + if sys.version_info[0] >=3 and sys.version_info[1] > 11: + from setuptools._distutils import ccompiler + else: + from distutils import ccompiler + compiler = ccompiler.new_compiler() + if compiler.compiler_type == "msvc": + for k in ["-std=c++11", "-fvisibility=hidden"]: # remove unsupported flags + try: + prefix_args.remove(k) + except ValueError: + pass + + cfg["compiler_args"] = prefix_args + cfg["compiler_args"] def get_rendered_source_filepath(filepath):