Hank
Hank

Reputation: 2626

How to create interface file for SWIG

I have the following header files: gaiageo.h which is defined as

#ifndef DOXYGEN_SHOULD_SKIP_THIS
/* stdio.h included for FILE objects. */
#include <stdio.h>
#ifdef DLL_EXPORT
#define GAIAGEO_DECLARE __declspec(dllexport)
#else
#define GAIAGEO_DECLARE extern
#endif
#endif

#ifndef _GAIAGEO_H
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#define _GAIAGEO_H
#endif

#include "gg_const.h"
#include "gg_structs.h"
#include "gg_core.h"
#include "gg_mbr.h"
#include "gg_formats.h"
#include "gg_dynamic.h"
#include "gg_advanced.h"

#endif /* _GAIAGEO_H */

The included header files are riddled with GAIAGEO_DECLARE, for instance gg_formats.h (which is very typical of the included headers) has the following:

/**
\file gg_formats.h

Geometry handling functions: formats
*/

#ifndef _GG_FORMATS_H
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#define _GG_FORMATS_H
#endif

#ifdef __cplusplus
extern "C"
{
#endif

/* function prototypes */

/**
 Test CPU endianness

 \return 0 if big-endian: any other value if little-endian
 */
    GAIAGEO_DECLARE int gaiaEndianArch (void);

/**
 Import an INT-16 value in endian-aware fashion

 \param p endian-dependent representation (input buffer).
 \param little_endian 0 if the input buffer is big-endian: any other value
 for little-endian.
 \param little_endian_arch the value returned by gaiaEndianArch()

 \return the internal SHORT value 

 \sa gaiaEndianArch, gaiaExport16

 \note you are expected to pass an input buffer corresponding to an
 allocation size of (at least) 2 bytes.
 */
    GAIAGEO_DECLARE short gaiaImport16 (const unsigned char *p,
                    int little_endian,
                    int little_endian_arch);
#ifdef __cplusplus
}
#endif

#endif  /* _GG_FORMATS_H */

This is my first attempt at creating interface files and would like some help, online documentation is confusing me?

Should I be creating an interface file for each header and how should I create the interface for the encompassing gaiageo.h?

Upvotes: 1

Views: 3805

Answers (1)

Mark Tolonen
Mark Tolonen

Reputation: 177901

This should get you started, but it is difficult to know exactly what you'll need.

%include <windows.i> makes SWIG handle Window-isms like __declspec(dllexport).

SWIG does not recurse include files by default, so include the ones you need SWIG to process. There is a switch to recurse, but then it would process stdio.h.

%module gaiageo

%{
#include "gaiageo.h"
%}

%include <windows.i>
%include "gaiageo.h"
%include "gg_const.h"
%include "gg_structs.h"
%include "gg_core.h"
%include "gg_mbr.h"
%include "gg_formats.h"
%include "gg_dynamic.h"
%include "gg_advanced.h"

Save that as a gaiageo.i file and run something like:

swig -c++ -<target_language> gaiageo.i

Upvotes: 4

Related Questions