##
#!/usr/local/bin/perl
use warnings;
use strict;
my $img = shift || die "Usage: perl inline.pl [tiff]\n";
my $gtif = 0;
if ( ! $gtif ) {
die "Couldn't use $img\n" unless use_tiff( $img );
tiff_cleanup();
} else {
die "Couldn't use $img\n" unless use_gtif( $img );
gtif_cleanup();
}
#---------------------------------------------------------------------------------------------------
use Inline C => Config =>
LIBS => '-lm -ltiff -L/usr/local/lib -lgeotiff',
# LIBS => '-lm -ltiff', # Works with $gtif = 0
INC => '-I/usr/local/include'
;
use Inline C => <<'END_OF_C_CODE';
#include
#include
#include
#include "geotiff.h"
#include "xtiffio.h"
#define DEBUG 1
TIFF *IMAGE; // TIFF image handle
GTIF *GEO_IMAGE; // GeoTIFF image handle
void check_image(TIFF *image) {
// Check that it is of a type that we support - if not throw errors
uint16 bps, spp;
if ( (TIFFGetField(image, TIFFTAG_BITSPERSAMPLE, &bps) == 0) || (bps != 8) )
throw_error("Either undefined or unsupported number of bits per sample.\n");
if ( (TIFFGetField(image, TIFFTAG_SAMPLESPERPIXEL, &spp) == 0) || (spp != 1) )
throw_error("Either undefined or unsupported number of samples per pixel.\n");
if ( TIFFIsTiled(image) == 0 )
throw_error("Image must be tiled.\n");
}
int use_tiff( const char *image_file ) {
if ( DEBUG == 1 )
printf( "TIFF file: %s\n", image_file );
// Open the TIFF image
if ( (IMAGE = TIFFOpen(image_file, "r")) == NULL ) {
throw_error("Could not open incoming image.\n");
}
check_image(IMAGE);
return 1;
}
int use_gtif( const char *image_file ) {
if ( DEBUG == 1 )
printf( "GTIF file: %s\n", image_file );
// Open the TIFF image
if ( (IMAGE = XTIFFOpen(image_file, "r")) == NULL ) {
throw_error("Could not open incoming image.\n");
}
check_image(IMAGE);
// Open the geotiff information handle on image
if ( (GEO_IMAGE = GTIFNew(IMAGE)) == NULL )
throw_error("Could not read geotiff data on image.\n");
return 1;
}
void tiff_cleanup() {
TIFFClose(IMAGE);
}
void gtif_cleanup() {
GTIFFree(GEO_IMAGE);
XTIFFClose(IMAGE);
}
void throw_error(char * msg) {
fprintf(stderr,msg);
exit(42);
}
END_OF_C_CODE
## ##
<-----------------------Information Section----------------------------------->
Information about the processing of your Inline C code:
Your source code needs to be compiled. I'll use this build directory:
/.../_Inline/build/inline04b_pl_8926
and I'll install the executable as:
/.../_Inline/lib/auto/inline04b_pl_8926/inline04b_pl_8926.so
The following Inline C function(s) have been successfully bound to Perl:
void gtif_cleanup()
void test()
void throw_error(char * msg)
void tiff_cleanup()
int use_gtif(const char * image_file)
int use_tiff(const char * image_file)
<-----------------------End of Information Section---------------------------->
Starting Build Preprocess Stage
Finished Build Preprocess Stage
Starting Build Parse Stage
Finished Build Parse Stage
Starting Build Glue 1 Stage
Finished Build Glue 1 Stage
Starting Build Glue 2 Stage
Finished Build Glue 2 Stage
Starting Build Glue 3 Stage
Finished Build Glue 3 Stage
Starting Build Compile Stage
Starting "perl Makefile.PL" Stage
Writing Makefile for inline04b_pl_5b15
Finished "perl Makefile.PL" Stage
Starting "make" Stage
/usr/bin/perl /usr/lib/perl5/5.8.8/ExtUtils/xsubpp -typemap /usr/lib/perl5/5.8.8/ExtUtils/typemap inline04b_pl_5b15.xs > inline04b_pl_5b15.xsc && mv inline04b_pl_5b15.xsc inline04b_pl_5b15.c
gcc -c -I... -I/usr/local/include -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -Wdeclaration-after-statement -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -DVERSION=\"0.00\" -DXS_VERSION=\"0.00\" -fPIC "-I/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE" inline04b_pl_5b15.c
Running Mkbootstrap for inline04b_pl_5b15 ()
chmod 644 inline04b_pl_5b15.bs
rm -f blib/arch/auto/inline04b_pl_5b15/inline04b_pl_5b15.so
gcc -shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic inline04b_pl_5b15.o -o blib/arch/auto/inline04b_pl_5b15/inline04b_pl_5b15.so \
-lm -ltiff -L/usr/local/lib -lgeotiff \
chmod 755 blib/arch/auto/inline04b_pl_5b15/inline04b_pl_5b15.so
cp inline04b_pl_5b15.bs blib/arch/auto/inline04b_pl_5b15/inline04b_pl_5b15.bs
chmod 644 blib/arch/auto/inline04b_pl_5b15/inline04b_pl_5b15.bs
Finished "make" Stage
Starting "make install" Stage
Installing .../_Inline/lib/auto/inline04b_pl_5b15/inline04b_pl_5b15.so
Installing .../_Inline/lib/auto/inline04b_pl_5b15/inline04b_pl_5b15.bs
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Writing .../_Inline/lib/auto/inline04b_pl_5b15/.packlist
Finished "make install" Stage
Starting Cleaning Up Stage
Finished Cleaning Up Stage
Finished Build Compile Stage
Had problems bootstrapping Inline module 'inline04b_pl_5b15'
Can't load '.../_Inline/lib/auto/inline04b_pl_5b15/inline04b_pl_5b15.so' for module inline04b_pl_5b15: libgeotiff.so: cannot open shared object file: No such file or directory at /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/DynaLoader.pm line 230.
at /usr/lib/perl5/site_perl/5.8.8/Inline.pm line 504
at inline04b.pl line 53
BEGIN failed--compilation aborted at inline04b.pl line 171.