[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] define-foreign record in shapelib

From: Ben Matasar
Subject: [Chicken-users] define-foreign record in shapelib
Date: Wed, 13 Sep 2006 12:10:30 -0700

Chicken people,

I'm trying to use chicken to call into shapelib, and I'm having a
devil of a time getting the FFI to work.  I can call into shapelib
problem, but I'm trying to declare a foreign record and am having
problems.  Here're the C declarations, from <shapefil.h>

typedef struct
   FILE        *fpSHP;
   FILE *fpSHX;

   int          nShapeType;                             /* SHPT_* */

   int          nFileSize;                              /* SHP file */

   int         nRecords;
   int          nMaxRecords;
   int          *panRecOffset;
   int          *panRecSize;

   double       adBoundsMin[4];
   double       adBoundsMax[4];

   int          bUpdated;

   unsigned char *pabyRec;
   int         nBufSize;
} SHPInfo;

typedef SHPInfo * SHPHandle;

typedef struct
   int          nSHPType;

   int          nShapeId; /* -1 is unknown/unassigned */

   int          nParts;
   int          *panPartStart;
   int          *panPartType;

   int          nVertices;
   double       *padfX;
   double       *padfY;
   double       *padfZ;
   double       *padfM;

   double       dfXMin;
   double       dfYMin;
   double       dfZMin;
   double       dfMMin;

   double       dfXMax;
   double       dfYMax;
   double       dfZMax;
   double       dfMMax;
} SHPObject;

I can include the functions like this:

typedef SHPInfo * SHPHandle;
SHPHandle SHPOpen( const char * pszShapeFile, const char * pszAccess );
void SHPGetInfo( SHPHandle hSHP, int * pnEntities, int * pnShapeType,
                 double * padfMinBound, double * padfMaxBound );
SHPObject *SHPReadObject( SHPHandle hSHP, int iShape );

(define info (SHPOpen "/Users/bmatasar/Desktop/at_tigeresri8287184920
Folder/blk0041039/tgr41039blk00.shp" "rb"))
(print (SHPReadObject info 0))

The output of this print is #<pointer 0x(number)>, so I believe it is
successfully calling the library.  To compile I am using:

$  csc shapeparse.scm -lshp

When I try to add a define-foreign-record, like this one:

(define-foreign-record (shpobject* "struct SHPObject")
 (integer nSHPType)
 (integer nShapeId)
 (integer nParts)

 (c-pointer panPartStart)
 (c-pointer panPartType)

 (integer nVertices)

 (c-pointer padfX)
 (c-pointer padfY)
 (c-pointer padfZ)
 (c-pointer padfM)

 (double dfXMin)
 (double dfYMin)
 (double dfZMin)
 (double dfMMin)
 (double dfXMax)
 (double dfYMax)
 (double dfZMax)
 (double dfMMax))

I get compilation errors all around:

shapeparse.c:426: error: dereferencing pointer to incomplete type

Can somebody point me in the right direction here?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]