ARPA-SIMC / fortrangis

A collection of Fortran interfaces to the most common Open Source GIS libraries.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I use this lib?

qmeng0903 opened this issue · comments

After configure and make, how can I use gdal lib? Do this program have examples?

I suggest to start from the gdal_test.F90 program, it is not just a test, but also a commented example on how to write and read a raster dataset from fortran.

I suggest to start from the gdal_test.F90 program, it is not just a test, but also a commented example on how to write and read a raster dataset from fortran.

How should I compile gdal_test.F90 ? Should I use ' gfortran -o gdal_test gdal_test.F90' or link other files and lib?

Within the build system, you can just do make check and it will compile all the *_test sources and run the tests.

In general, after you have built the library, you should follow the standard autoconf/automake procedures, that means installing the libraries and header files somewhere with make install (if you want to change the default install path you have to preliminary run configure --prefix=<installprefix>).
After installation, assuming that you installed in a nonsytem location, in order to compile a custom program (such as gdal_test.F90, but let's call it mygdalprogram.F90 now) you will have to do as follows:

gfortran -I<installprefix>/include -o mygdalprogram mygdalprogram.F90 \
 -L<installprefix>/lib -lfortrangis -lfortranc

and, again assuming that you installed in a nonsystem location, before executing mygdalprogram you may probably need to do export LD_LIBRARY_PATH=<installprefix>/lib:$LD_LIBRARY_PATH.

These are general guidelines for building and using custom libraries on linux, they are not specific to fortrangis.

Within the build system, you can just do make check and it will compile all the *_test sources and run the tests.

In general, after you have built the library, you should follow the standard autoconf/automake procedures, that means installing the libraries and header files somewhere with make install (if you want to change the default install path you have to preliminary run configure --prefix=<installprefix>).
After installation, assuming that you installed in a nonsytem location, in order to compile a custom program (such as gdal_test.F90, but let's call it mygdalprogram.F90 now) you will have to do as follows:

gfortran -I<installprefix>/include -o mygdalprogram mygdalprogram.F90 \
 -L<installprefix>/lib -lfortrangis -lfortranc

and, again assuming that you installed in a nonsystem location, before executing mygdalprogram you may probably need to do export LD_LIBRARY_PATH=<installprefix>/lib:$LD_LIBRARY_PATH.

These are general guidelines for building and using custom libraries on linux, they are not specific to fortrangis.

Thank you very much ! I successed by doing make check , and it also work well run gfortran -DHAVE_CONFIG_H -I. -I.. -I../libfortranc -g -O2 -O -c -o gdal_test-test.o gdal_test.F90 and /bin/bash ../libtool --tag=FC --mode=link gfortran -I../libfortranc -g -O2 -O -o gdal_test gdal_test-test.o libfortrangis.la ../libfortranc/libfortranc.la -L/usr/lib -lgdal, which copy from make check. But when I try to do as you said:
gfortran -I<installprefix>/include -o mygdalprogram mygdalprogram.F90 \ -L<installprefix>/lib -lfortrangis -lfortranc
it had 1 error:
/usr/bin/ld: /tmp/ccQ4Tk3v.o: undefined reference to symbol 'GDALSetRasterColorInterpretation' /usr/bin/ld: /lib/libgdal.so.28: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status
Can you tell me what went wrong ? Which lib did not I link ?
Thank you again !

sorry I forgot to finalize this issue, you probably needed to add -lgdal, i.e. the reference to the original gdal C library.