我尝试编译这个C++/Python库
https://bitbucket.org/fluiddyn/fluidfft
如果安装了mpi4py,则工作正常。
如果未安装mpi4py,则无法编译不使用MPI的代码。
编译Cython文件时出错。错误很长,从以下开始:
In file included from /usr/include/c++/6/bits/ios_base.h:46:0,
from /usr/include/c++/6/ios:42,
from /usr/include/c++/6/ostream:38,
from /usr/include/c++/6/iostream:39,
from src_cpp/base/base_fft.h:10,
from fluidfft/fft2d/fft2d_with_fftw1d.cpp:543:
/usr/include/c++/6/system_error:143:31: error: âerror_categoryâ does not name a type
error_code(int __v, const error_category& __cat) noexcept
^~~~~~~~~~~~~~
/usr/include/c++/6/system_error:152:27: error: âerror_categoryâ does not name a type
assign(int __v, const error_category& __cat) noexcept
^~~~~~~~~~~~~~
/usr/include/c++/6/system_error:172:11: error: âerror_categoryâ does not name a type
const error_category&
^~~~~~~~~~~~~~
/usr/include/c++/6/system_error:191:11: error: âerror_categoryâ does not name a type
const error_category* _M_cat;
[...]
我想这可能是C++11的问题(
http://en.cppreference.com/w/cpp/error/error_category
)但我不知道如何解决这个问题。
编译命令为
g++ -pthread -fwrapv -O3 -Wall -Wno-unused-result -Wsign-compare -Wno-unused-result -Wsign-compare -fwrapv -O3 -Wall -fPIC -I/home/users/me/opt/miniconda3/include/python3.6m -I/home/users/me/opt/miniconda3/include -Isrc_cy -Ifluidfft/fft2d -Ifluidfft/fft3d -Isrc_cpp/base -Isrc_cpp/3d -Isrc_cpp/2d -Iinclude -I/home/users/me/opt/miniconda3/lib/python3.6/site-packages/numpy/core/include -c fluidfft/fft2d/fft2d_with_fftw1d.cpp -o build/temp.linux-x86_64-3.6/fluidfft/fft2d/fft2d_with_fftw1d.o
编辑最小、完整且可验证的示例
感谢Ashwin Vishnu(参见
https://bitbucket.org/fluiddyn/fluidfft/issues/7/fluidfft-installation-fails-without-mpi4py
),我可以发布一个简单的示例
/* test.cpp */
#include <Python.h>
#include <string.h>
#include <stdio.h>
#include <cpu.h>
#include <sys/time.h>
#include <complex>
#include <iostream>
int main() {
std::cout<<"Hello world";
return 0;
}
从fluidfft目录编译如下:
g++ $(python-config --include) -Iinclude/ test.cpp
如果我们注释掉cpu。h包括,没有错误。
文件cpu。h取自pyfftw代码:
https://github.com/pyFFTW/pyFFTW/blob/master/include/cpu.h