[GRASS-dev] getting SWIG/Python to work

Hamish hamish_nospam at yahoo.com
Thu May 17 01:35:08 EDT 2007


A couple of issues here:

should "./configure --with-python" trigger make swig/python somehow?
(currently you have to manually run make)
Running make in the swig/ dir is a no-op.
See missing Python.h problem below, check for that too?


As per the readme, I had to install the 'swig' package to get going.
Add check for [-x `which swig`] to ./configure if --with-python?
(make exited with error the first time as it was missing)


make distclean doesn't clean these: (they are auto-generated by Makefile)
? interfaces/dig_structs.i
? interfaces/gisdefs.i
? interfaces/vect.i

this patch ok?

Index: swig/python/interfaces/Makefile
===================================================================
RCS file: /home/grass/grassrepository/grass6/swig/python/interfaces/Makefile,v
retrieving revision 1.7
diff -u -r1.7 Makefile
--- swig/python/interfaces/Makefile     14 May 2007 10:03:06 -0000      1.7
+++ swig/python/interfaces/Makefile     17 May 2007 04:19:38 -0000
@@ -13,3 +13,5 @@
        echo "/* auto-generate swig typedef file */" > vect.i
        cat ../../../include/Vect.h | grep -v 'V1_\|V2_' >> vect.i
 
+distclean:
+       -rm -f gisdefs.i dig_structs.i vect.i




grass63/swig/python$ make           
Makefile:21: warning: overriding commands for target `clean'
../../include/Make/Rules.make:34: warning: ignoring old commands for target `clean'
gcc -c -fpic -I/usr/include/python2.3 -I./ -I/usr/local/src/grass/grass63/dist.i686-pc-linux-gnu/include  python_grass6_wrap.c
python_grass6_wrap.c:22:20: Python.h: No such file or directory
python_grass6_wrap.c:622: error: syntax error before "PyObject_HEAD"
python_grass6_wrap.c:622: warning: no semicolon at end of struct or union
python_grass6_wrap.c:625: error: syntax error before '}' token
python_grass6_wrap.c:625: warning: data definition has no type or storage class
python_grass6_wrap.c:630: error: syntax error before '*' token
python_grass6_wrap.c: In function `PySwigObject_print':
python_grass6_wrap.c:633: error: `v' undeclared (first use in this function)
python_grass6_wrap.c:633: error: (Each undeclared identifier is reported only once
python_grass6_wrap.c:633: error: for each function it appears in.)
python_grass6_wrap.c:634: error: `fp' undeclared (first use in this function)
python_grass6_wrap.c: At top level:
python_grass6_wrap.c:641: error: syntax error before '*' token
python_grass6_wrap.c:642: error: syntax error before '*' token
python_grass6_wrap.c: In function `PySwigObject_repr':
python_grass6_wrap.c:645: error: `v' undeclared (first use in this function)
python_grass6_wrap.c:646: warning: return makes pointer from integer without a cast
python_grass6_wrap.c: At top level:
python_grass6_wrap.c:649: error: syntax error before '*' token
python_grass6_wrap.c:650: error: syntax error before '*' token
[...]
[...]
[...]

$ locate Python.h
[nothing]

$ apt-file search Python.h | grep -v Python.html
libsidl-dev: usr/include/sidl_Python.h
python2.1-dev: usr/include/python2.1/Python.h
python2.2-dev: usr/include/python2.2/Python.h
python2.3-dev: usr/include/python2.3/Python.h
python2.4-dev: usr/include/python2.4/Python.h

$ ls -l /usr/bin/python
... /usr/bin/python -> python2.3

# apt-get install python2.3-dev
[whiz,bang,whirl]

grass63/swig/python$ make
Makefile:21: warning: overriding commands for target `clean'
../../include/Make/Rules.make:34: warning: ignoring old commands for target `clean'
gcc -c -fpic -I/usr/include/python2.3 -I./ -I/usr/local/src/grass/grass63/dist.i686-pc-linux-gnu/include  python_grass6_wrap.c
python_grass6_wrap.c: In function `_wrap_Categories_labels_get':
python_grass6_wrap.c:9151: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_Key_Value_key_get':
python_grass6_wrap.c:12128: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_Key_Value_value_get':
python_grass6_wrap.c:12189: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_Option_opts_get':
python_grass6_wrap.c:12511: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_Option_descs_get':
python_grass6_wrap.c:12760: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_Option_answers_get':
python_grass6_wrap.c:12915: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_G_list':
python_grass6_wrap.c:26292: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_G__ls':
python_grass6_wrap.c:26672: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_G_available_mapsets':
python_grass6_wrap.c:27240: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_G_tokenize':
python_grass6_wrap.c:34387: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
python_grass6_wrap.c: In function `_wrap_SITE_ATT_str_get':
python_grass6_wrap.c:49748: warning: passing arg 1 of `PyList_SetItem' from incompatible pointer type
ld -shared -L/usr/local/src/grass/grass63/dist.i686-pc-linux-gnu/lib -lgrass_I -lgrass_Iortho -lgrass_bitmap -lgrass_btree -lgrass_cdhc -lgrass_datetime -lgrass_dbmibase -lgrass_dbmiclient -lgrass_dbmidriver -lgrass_dbstubs -lgrass_dgl -lgrass_display -lgrass_dspf -lgrass_edit -lgrass_form -lgrass_g3d -lgrass_gis -lgrass_gmath -lgrass_gproj -lgrass_interpdata -lgrass_interpfl -lgrass_linkm -lgrass_qtree -lgrass_raster -lgrass_rowio -lgrass_rtree -lgrass_segment -lgrass_shape -lgrass_sites -lgrass_symb -lgrass_trans -lgrass_vask -lgrass_vect -lgrass_psdriver python_grass6_wrap.o -o _python_grass6.so



Are those incompatible pointer type warnings meaningful?


grass63/swig/python$ ls -l python_grass6.py _python_grass6.so
... 1030944 May 17 16:52 _python_grass6.so
...  277076 May 17 16:47 python_grass6.py
[success!]


"make -C interfaces/" didn't run. (why not?) I had to go into the subdir
and run make manually to generate gisdefs.i, dig_structs.i, and vect.i.


from the README:
------------------------
How to use it?
--------------

import python_grass6
GRASS functions will be available in this module.
Eg: 
        import python_grass6
        mapset=python_grass6.G_mapset()
        print mapset
-------------------------

G63> cd swig/python/
G63> python

Python 2.3.5 (#2, Oct 16 2006, 19:19:48) 
[GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import python_grass6
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "python_grass6.py", line 5, in ?
    import _python_grass6
ImportError: ./_python_grass6.so: undefined symbol: Vect_snap_lines_list


swig/python$ grep interfaces *.i
python_grass6.i:%include "interfaces/gis.i"
python_grass6.i:%include "interfaces/gisdefs.i"
python_grass6.i:%include "interfaces/imagery.i"
python_grass6.i:%include "interfaces/imagedefs.i"
python_grass6.i:%include "interfaces/vect.i"
python_grass6.i:%include "interfaces/dig_structs.i"
python_grass6.i:%include "interfaces/dig_types.i"

swig/python$ grep Vect_snap_lines_list python_grass6.py
Vect_snap_lines_list = _python_grass6.Vect_snap_lines_list


swig/python$ grep Vect_snap_lines_list interfaces/*.i  
interfaces/vect.i:void Vect_snap_lines_list (struct Map_info *, struct ilist *, double, struct Map_info *, FILE *);


swig/python$ ldd _python_grass6.so  | grep vect
  libgrass_vect.so => /usr/lib/grass/lib/libgrass_vect.so (0x40271000)


ahh, it is using /usr/lib/grass/lib/ (Debian 6.0.2 package install) not
/usr/src/grass/grass63/dist.i686-pc-linux-gnu/lib  build dir.


swig/python/Makefile:
...
LDFLAGS=-shared -L$(ARCH_LIBDIR) -lgrass_I -lgrass_Iortho [...]


why doesn't it respect -L$(ARCH_LIBDIR) as other things calling
  include $(MODULE_TOPDIR)/include/Make/Lib.make
do??
I've always had /usr/lib/grass/lib/ there, never a problem before.
(Debian's libgrass package is a needed prereq for the libgdal1-1.3.1-grass
[the GDAL GRASS plugin] and qgis-plugin-grass packages)


# apt-get remove libgrass

swig/python$ make clean && make && make -C interfaces
[ok]

swig/python$ ldd _python_grass6.so | grep vect
        libgrass_vect.so => not found

mmmph!


thanks,
Hamish




More information about the grass-dev mailing list