简体   繁体   English

在Windows中编译SWIG python包装程序时,MinGW g ++找不到numpy \\ arrayobject.h

[英]numpy\arrayobject.h not find by MinGW g++ while compiling SWIG python wrapper in Windows

On my debian distribution, I managed to build a python module in C++ using SWIG. 在我的debian发行版中,我设法使用SWIG在C ++中构建了一个python模块。 The module Amod can be imported succesfully in more complex python code and work fine. 可以使用更复杂的python代码成功导入Amod模块, Amod可以正常工作。 Here the compilation used on Linux : 这是在Linux上使用的编译:

swig -c++ -python test5.i
g++ -fPIC -c test5.cpp
g++ -fPIC -c test5_wrap.cxx -I/usr/include/python2.7
g++ -shared test5.o test5_wrap.o -o _Amod.so

But now I want recomplie it on Windows, and I am not sure of what I am doing. 但是现在我想在Windows上重新编译它,而且我不确定自己在做什么。

I installed numpy 1.7.0. 我安装了numpy 1.7.0。 and MinGW with g++, and I added path for swig in the "PATH" environment variable, as explained in the SWIG doc. 以及使用g ++的MinGW,我在“ PATH”环境变量中添加了swig的路径,如SWIG文档中所述。 I added also path to my Python 2.7.5 installation and to Python.h. 我还为我的Python 2.7.5安装和Python.h添加了路径。

I open the windows terminal and type : 我打开Windows终端并输入:

swig -c++ -Wall -python test5.i
g++ -c -Wall test5.cpp

It compiles without problems. 它编译没有问题。 then 然后

g++ -c test5_wrap.cxx 

fatal error: Python.h: no such file or directory . fatal error: Python.h: no such file or directory I don't get it, the path to Python.h isn't in the PATH variable !? 我不明白,Python.h的路径不在PATH变量中! so I type 所以我输入

g++ -c test5_wrap.cxx -I C:\Python27\include

fatal error: numpy\\arrayobject.h: no such file or directory . fatal error: numpy\\arrayobject.h: no such file or directory I don't get it either, this header exists in C:\\Python27\\Lib\\site-packages\\numpy\\core\\include\\numpy\\ . 我也不明白,此标头存在于C:\\Python27\\Lib\\site-packages\\numpy\\core\\include\\numpy\\ Then I tried 然后我尝试

g++ -c test5_wrap.cxx -I C:\Python27\include C:\Python27\Lib\site-packages\numpy\core\include\numpy\

same error and so I tried : 同样的错误,所以我尝试了:

g++ -c test5_wrap.cxx -I C:\Python27\include C:\Python27\Lib\site-packages\numpy\core\include\numpy\arrayobject.h

give a huge pile of errors beginning with the same fatal error: numpy\\arrayobject.h: no such file or directory . 从相同的fatal error: numpy\\arrayobject.h: no such file or directory错误开始,给出大量fatal error: numpy\\arrayobject.h: no such file or directory

How solve that ? 如何解决呢? Is MinGW + SWIG + g++ the right direction for my python module compilation ? MinGW + SWIG + g ++是我的python模块编译的正确方向吗?

Thanks a lot. 非常感谢。

FM 调频

Edit : Meanwhile I tried also to compile this python module with distutils with this setup.py : 编辑:同时,我也尝试与此setup.py用distutils编译此python模块:

# -*- coding: utf-8 -*-
"""
Created on Wed Oct 23 17:01:51 2013

@author: Florian
"""
from distutils.core import setup, Extension


Amod = Extension('_Amod',
                           sources=['test5_wrap.cxx', 'test5.cpp'],
                           )

setup (name = 'Amod',
       version = '0.1',
       author      = "FM",
       description = """Come on""",
       ext_modules = [Amod],
       py_modules = ["Amod"],
       )

And compiling with : 并使用:

python setup.py build_ext --compiler=mingw32 --swig-opts="-c++ -I :C/Python27/include -I :C/Python27/Lib/site-packages/numpy/core/include/"

And still this dammit error : 而且仍然是该死的错误:

running build_ext
building '_Amod' extension
C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Python27\include -IC:\Python27\PC -c test5_wrap.cxx -o build\temp.win32-2.7\Rel
ease\test5_wrap.o
test5_wrap.cxx:3045:31: fatal error: numpy/arrayobject.h: No such file or directory
 #include <numpy/arrayobject.h>

I googled the error undefined reference to _imp__Py... that I got with my first try, but people talk about missing linked library, I don't see which library I should link and why. 我在第一次尝试时就搜索undefined reference to _imp__Py...的错误undefined reference to _imp__Py... ,但是人们谈论缺少链接库,我看不到我应该链接哪个库以及为什么链接。 It's a bit over my skills. 我的技能有点过分了。

Try changing it to -IC:\\Python27\\include -IC:\\Python27\\Lib\\site-packages\\numpy\\core\\include . 尝试将其更改为-IC:\\Python27\\include -IC:\\Python27\\Lib\\site-packages\\numpy\\core\\include Those paths are needed so gcc knows where to search for the include headers. 这些路径是必需的,因此gcc知道在哪里搜索include标头。

In a *nix environment, there are likely environment variables and other implicit search paths gcc looks in when looking for include headers and that's probably why it compiles successfully . 在* nix环境中,gcc在寻找include标头时可能会查找环境变量和其他隐式搜索路径,这可能就是它成功编译的原因。 On windows mingw, however, you'll have to specify those paths explicitly so it looks in the right place. 但是,在Windows mingw上,您必须显式指定这些路径,以便它在正确的位置显示。

I had the same problem in cygwin while compiling a c++ code. 在编译c ++代码时,我在cygwin中遇到了同样的问题。 Solution was to install python2-devel and python2-numpy, and then use the command "python -m site" in order to see the python installation directories. 解决方法是先安装python2-devel和python2-numpy,然后使用命令“ python -m site”以查看python安装目录。 Use the following find command to locate the header file: find /usr/lib/python2.7 -name "*.h". 使用以下find命令查找头文件:find /usr/lib/python2.7 -name“ * .h”。 The header files are under directory /usr/lib/python2.7/site-packages/numpy/core/include. 头文件位于目录/usr/lib/python2.7/site-packages/numpy/core/include下。 Include this path with the following include option to the g++ command: -I/usr/lib/python2.7/site-packages/numpy/core/include. 使用g ++命令的以下include选项将此路径包括在内:-I / usr / lib / python2.7 / site-packages / numpy / core / include。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM