Cython 构建找不到 C++11 STL 文件 - 但仅当从 setup.py 调用时

Cython build can't find C++11 STL files - but only when called from setup.py

当我从 setup.py 编译我的代码时,它找不到 C++11 包含文件 <array> - 但 C++11 编译器功能确实有效。

当我将 setup.py 生成的相同命令行粘贴到我的 shell 时,它都编译得很好(!)

可以看到演示此行为的代码 here 并且也粘贴在下面。


终端会话:

$ python setup.py build_ext
running build_ext
building 'simple' extension
creating build
creating build/temp.macosx-10.6-intel-3.4
/usr/bin/clang -fno-strict-aliasing -Werror=declaration-after-statement -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch i386 -arch x86_64 -g -Isrc -I/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4m -c simple.cpp -o build/temp.macosx-10.6-intel-3.4/simple.o -Wno-unused-function -std=c++11
In file included from simple.cpp:289:
./simple.h:2:10: fatal error: 'array' file not found
#include <array>
         ^
1 error generated.
error: command '/usr/bin/clang' failed with exit status 1

$ /usr/bin/clang -fno-strict-aliasing -Werror=declaration-after-statement -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch i386 -arch x86_64 -g -Isrc -I/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4m -c simple.cpp -o build/temp.macosx-10.6-intel-3.4/simple.o -Wno-unused-function -std=c++11

# no error!

$  /usr/bin/clang --version
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

setup.py:

#!/usr/bin/env python3

import platform, distutils.core, distutils.extension, Cython.Build

EXTENSION = distutils.extension.Extension(
    name='simple',
    sources=['simple.pyx'],
    extra_compile_args=['-Wno-unused-function', '-std=c++11'],
    language='c++',
    )

EXT_MODULES=Cython.Build.cythonize(
    [EXTENSION],
    language='c++',
    )

distutils.core.setup(
    name='simple',
    ext_modules=EXT_MODULES,
    )

simple.pyx:

cdef extern from "simple.h" namespace "fcolor4":
    struct Simple:
        int x

simple.h:

int foo() {
    auto x = 1;   // works, so must be C++11
    return x;
}

#include <string>  // works, so must find some STL.
#include <array>   // fails!

我相信这与我之前遇到的问题相同 。就我而言,问题似乎是 setuptools 使用了与编译 Python 解释器时相同的编译器标志,其中包括一个使代码与相当旧版本的 Mac 兼容的标志OS X(远远早于 C++11)。

尝试将标志 -mmacosx-version-min=10.9(或更高版本)添加到 setup.py 中的 extra_compile_args