[Python] cython e warning: no library file corresponding to 'grass/raster.h' found (skipping)

Pietro peter.zamb a gmail.com
Mer 10 Lug 2013 15:08:37 CEST


Ciao,

vorrei provare ad utilizzare Cython[0] per interfacciarmi ad alcune
librerie C di GRASS [1], attualmente sto utilizzando ctypes.
Ho creato un repository di prova: https://github.com/zarch/cygrass

Quando compilo con cython ottengo:

$ CFLAGS="-I/home/pietro/docdat/src/gis/grass/grass_trunk/dist.x86_64-unknown-linux-gnu/include"
 \
> LDFLAGS="-L/home/pietro/docdat/src/gis/grass/grass_trunk/dist.x86_64-unknown-linux-gnu/lib"     \
> python setup.py build_ext --inplace --force
running build_ext
cythoning raster.pyx to raster.c
building 'raster' extension
gcc -pthread -DNDEBUG -march=x86-64 -mtune=generic -O2 -pipe
-fstack-protector --param=ssp-buffer-size=4
-I/home/pietro/docdat/src/gis/grass/grass_trunk/dist.x86_64-unknown-linux-gnu/include
-fPIC -I/home/pietro/docdat/src/gis/grass/grass_trunk/dist.x86_64-unknown-linux-gnu/include
-I/usr/include/python2.7 -c raster.c -o
build/temp.linux-x86_64-2.7/raster.o
warning: no library file corresponding to 'grass/raster.h' found (skipping)
gcc -pthread -shared -Wl,-O1,--sort-common,--as-needed,-z,relro
-L/home/pietro/docdat/src/gis/grass/grass_trunk/dist.x86_64-unknown-linux-gnu/lib
-I/home/pietro/docdat/src/gis/grass/grass_trunk/dist.x86_64-unknown-linux-gnu/include
build/temp.linux-x86_64-2.7/raster.o -L/usr/lib -lpython2.7 -o
/home/pietro/docdat/src/gis/grass/grass_trunk/lib/python/cygrass/raster.so


Non trova il file: 'grass/raster.h' ma il file esiste...

$ du -h /home/pietro/docdat/src/gis/grass/grass_trunk/dist.x86_64-unknown-linux-gnu/include/grass/raster.h
8.0K    /home/pietro/docdat/src/gis/grass/grass_trunk/dist.x86_64-unknown-linux-gnu/include/grass/raster.h

Il file setup.py č cosė definito:

###
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

setup(
    cmdclass={'build_ext': build_ext},
    ext_modules=[Extension("raster", ["raster.pyx"],

include_dirs=["/home/pietro/docdat/src/gis/grass/grass_trunk/dist.x86_64-unknown-linux-gnu/include",
],
                           libraries=["grass/raster.h", ])]
)
###

mentre il file raster.pyx definisce una funzione stupida di prova tipo:

###
cimport crast

cpdef crast.RASTER_MAP_TYPE mtype2gtype(char *mtype):
    if mtype[0] == 'C':
        return crast.CELL_TYPE
    elif mtype[0] == 'F':
        return crast.FCELL_TYPE
    elif mtype[0] == 'D':
        return crast.DCELL_TYPE
    else:
        print 'Error: mtype not valid.'
        return 0
###

Risco ad importare la libreria ma non ad utilizzare la funzione che ho definito.

In [1]: import raster
In [2]: raster.mtype2gtype('CELL')
Exception NameError: "name 'crast' is not defined" in
'raster.mtype2gtype' ignored
Out[2]: 0
In [3]: raster.mtype2gtype('FCELL')
Exception NameError: "name 'crast' is not defined" in
'raster.mtype2gtype' ignored
Out[3]: 0


C'č qualcuno con pių esperienza che riesce a capire cosa sto sbagliando?

Grazie per l'aiuto.

Pietro

[0] Cython - http://cython.org/
[1] GRASS - http://grass.osgeo.org/


Maggiori informazioni sulla lista Python