Cython构建无法找到C++ 11 STL文件 - 但仅在从setup.py调用时才能找到

Tom*_*rly 5 python cython c++11

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

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

可以在此处看到演示此行为的代码,并在下面粘贴.


终端会议:

$ 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
Run Code Online (Sandbox Code Playgroud)

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,
    )
Run Code Online (Sandbox Code Playgroud)

simple.pyx:

cdef extern from "simple.h" namespace "fcolor4":
    struct Simple:
        int x
Run Code Online (Sandbox Code Playgroud)

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!
Run Code Online (Sandbox Code Playgroud)

jb3*_*326 6

我相信这是我之前有同样的问题在这里.在我的例子中,问题似乎是setuptools使用与Python解释器编译时相同的编译器标志,并且这些标志包含一个标志,使得代码与相当旧版本的Mac OS X兼容(远在C之前) ++ 11).

尝试在您的标记中添加标记-mmacosx-version-min=10.9(或更高版本).extra_compile_argssetup.py