gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 01:00:12 26 4
gpt4 key购买 nike

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

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

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


终端 session :

$ 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

设置.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,
)

简单.pyx:

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

简单.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!

最佳答案

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

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

关于python - Cython build 找不到 C++11 STL 文件 - 但仅当从 setup.py 调用时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36960587/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com