使用 swig 和 python 设置编译器标志
Setting compiler flags using swig and python
我在将 boost 包含到我的 C++ 代码中时遇到问题,该代码是使用 'swig' 编译的。我想用 C++ 作为我的 python 东西的后端。
调用这两个命令
swig -c++ -python spherical_overlap.i
python setup.py build_ext --inplace
后者给我以下错误
clang: warning: -lboost_system : 'linker' input unused
In file included from spherical_overlap_wrap.cxx:3427:
./spherical_overlap.h:8:10: fatal error: 'boost/math/special_functions/bessel.hpp' file not found
#include <boost/math/special_functions/bessel.hpp>
文件位于此处。我想我必须为编译器设置以下标志
-I /usr/local/include
问题是,我不知道该怎么做。这是我的 'setup.py' 文件
#!/usr/bin/env python
from distutils.core import setup, Extension
spherical_overlap_module = Extension('_spherical_overlap',
sources=['spherical_overlap_wrap.cxx', 'spherical_overlap.cpp'],
swig_opts=['-c++', '-py3'],
extra_compile_args =['-lboost_system '],
)
setup (name = 'spherical_overlap',
version = '0.1',
author = "SWIG Docs",
description = """Simple swig spherical_overlap from docs""",
ext_modules = [spherical_overlap_module],
py_modules = ["spherical_overlap"],
)
您可以执行以下任一操作:
将include_dirs = ['/usr/local/include'],
添加到Extension
构造函数调用
将以下内容添加到文件 setup.cfg
:
[build_ext]
include-dirs = /usr/local/include
为build_ext
命令指定include-dirs
选项,即运行
python setup.py build_ext --inplace --include-dirs /usr/local/include
将-I/usr/local/include
添加到CPPFLAGS
环境变量,例如运行
CPPFLAGS="-I/usr/local/include" python setup.py build_ext --inplace
可能第二种方式是首选方式,因为它反映了取决于本地系统配置的选项。
我在将 boost 包含到我的 C++ 代码中时遇到问题,该代码是使用 'swig' 编译的。我想用 C++ 作为我的 python 东西的后端。
调用这两个命令
swig -c++ -python spherical_overlap.i
python setup.py build_ext --inplace
后者给我以下错误
clang: warning: -lboost_system : 'linker' input unused
In file included from spherical_overlap_wrap.cxx:3427:
./spherical_overlap.h:8:10: fatal error: 'boost/math/special_functions/bessel.hpp' file not found
#include <boost/math/special_functions/bessel.hpp>
文件位于此处。我想我必须为编译器设置以下标志
-I /usr/local/include
问题是,我不知道该怎么做。这是我的 'setup.py' 文件
#!/usr/bin/env python
from distutils.core import setup, Extension
spherical_overlap_module = Extension('_spherical_overlap',
sources=['spherical_overlap_wrap.cxx', 'spherical_overlap.cpp'],
swig_opts=['-c++', '-py3'],
extra_compile_args =['-lboost_system '],
)
setup (name = 'spherical_overlap',
version = '0.1',
author = "SWIG Docs",
description = """Simple swig spherical_overlap from docs""",
ext_modules = [spherical_overlap_module],
py_modules = ["spherical_overlap"],
)
您可以执行以下任一操作:
将
include_dirs = ['/usr/local/include'],
添加到Extension
构造函数调用将以下内容添加到文件
setup.cfg
:[build_ext] include-dirs = /usr/local/include
为
build_ext
命令指定include-dirs
选项,即运行python setup.py build_ext --inplace --include-dirs /usr/local/include
将
-I/usr/local/include
添加到CPPFLAGS
环境变量,例如运行CPPFLAGS="-I/usr/local/include" python setup.py build_ext --inplace
可能第二种方式是首选方式,因为它反映了取决于本地系统配置的选项。