Python Cython与C++;|编译错误(未找到C+;+;头)| macOS 我试图在MaOS中使用Cython实现一个非常简单的C++代码。这是我的C++代码的头(它是一个文件名为 CSyTest.H./Cult>< /P> #include<iostream> void cs_test(int n);
这是我的Python Cython与C++;|编译错误(未找到C+;+;头)| macOS 我试图在MaOS中使用Cython实现一个非常简单的C++代码。这是我的C++代码的头(它是一个文件名为 CSyTest.H./Cult>< /P> #include<iostream> void cs_test(int n);,python,c++,macos,cython,cythonize,Python,C++,Macos,Cython,Cythonize,这是我的pyx代码(文件名:simulate.pyx) 最后,这是我的设置代码(setup.py) 上述所有文件都在同一文件夹中。我使用以下命令运行setup.py: python setup.py build_ext --inplace 并且,我得到以下错误消息: In file included from simulate.c:502:0: ./cauchy.h:1:19: fatal error: iostream: No such file or directory compilati
pyx
代码(文件名:simulate.pyx
)
最后,这是我的设置代码(setup.py
)
上述所有文件都在同一文件夹中。我使用以下命令运行setup.py
:
python setup.py build_ext --inplace
并且,我得到以下错误消息:
In file included from simulate.c:502:0:
./cauchy.h:1:19: fatal error: iostream: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
在simulate.pyx
中,即使我将“/cauchy.h”nogil:中的行cdef-extern替换为“cauchy.h”中的cdef-externnogil:
,我仍然收到相同的错误消息。我知道关于使用gcc
的错误消息可能是因为我在使用macOS。但是,我不知道如何让代码知道使用clang++
或c++
我在这里做了什么?我很感谢有帮助。
< P>这是我的安装文件。我还把C++代码的头文件改名成与C++文件的名称匹配。
import numpy
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [Extension(
name="simulate_cy",
sources=["simulate.pyx", "cs_test.cpp"],
# extra_objects=["fc.o"], # if you compile fc.cpp separately
include_dirs = [numpy.get_include()], # .../site-
packages/numpy/core/include
language="c++",
# libraries=
extra_compile_args = ['-O3'],
# extra_link_args = "...".)
)]
setup(
name = 'simulate_cy',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules,)
这是为我工作的安装文件。我还重命名C++代码的头文件,以匹配C++文件的名称。< /P>
import numpy
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [Extension(
name="simulate_cy",
sources=["simulate.pyx", "cs_test.cpp"],
# extra_objects=["fc.o"], # if you compile fc.cpp separately
include_dirs = [numpy.get_include()], # .../site-
packages/numpy/core/include
language="c++",
# libraries=
extra_compile_args = ['-O3'],
# extra_link_args = "...".)
)]
setup(
name = 'simulate_cy',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules,)
<> >让Cython生成和编译带有ditudil的C++代码,您只需要通过选项>代码>语言=“C++”< /> >:
这一点在报告中有明确说明
<> >让Cython生成和编译带有ditudil的C++代码,您只需要通过选项>代码>语言=“C++”< /> >:
这一点在上有明确说明。在cauchy.h
中添加#include
。或者可能是#include
。您可能需要将#include
添加到cs#u test.cpp
。您可能应该避免使用命名空间std
。相反,使用std::cout
,std::endl
,等等。@jww:de>#include
。我收到了相同的错误消息。您是否尝试在setup.py
文件中指定language=“c++”
(根据文档:)@邪恶羊:你提到的文档很有效。目前,我正在尝试它的一个变体,效果非常好。谢谢你的帮助。请让你的标题描述这个问题,而不仅仅是列出技术。在cauchy.h
中添加\include
。或者\include
。你可能会需要将#include
添加到cs_test.cpp
。您可能应该避免使用名称空间std
。相反,使用std::cout
、std::endl
等。@jww:我尝试了#include
。我收到了相同的错误消息。您是否尝试过在setup.py
文件中指定language=“c++”
(根据文档:)@UnholySheep:您提到的文档有效。目前,我正在尝试该文档的一个变体,效果非常好。感谢您的帮助。请让您的标题描述问题,而不仅仅是列出技术。
In file included from simulate.c:502:0:
./cauchy.h:1:19: fatal error: iostream: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
import numpy
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [Extension(
name="simulate_cy",
sources=["simulate.pyx", "cs_test.cpp"],
# extra_objects=["fc.o"], # if you compile fc.cpp separately
include_dirs = [numpy.get_include()], # .../site-
packages/numpy/core/include
language="c++",
# libraries=
extra_compile_args = ['-O3'],
# extra_link_args = "...".)
)]
setup(
name = 'simulate_cy',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules,)
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize(
"rect.pyx", # our Cython source
sources=["Rectangle.cpp"], # additional source file(s)
language="c++", # generate C++ code
))