Cyrus4ever
Cyrus4ever

Reputation: 81

Using typedef with SWIG

I have a C header file containing structure definitions with typedef, and an array of char definition with typedef too:

/* File: test.h */

typedef struct
{
    char *key;
    void *value;
    int size;
} cti_pair;

typedef char FOO[CONST];

The SWIG interface file contains the following lines:

/* File: test.i */
%module test

%{
#define SWIG_FILE_WITH_INIT
#include "/home/users/jdoe/workspace/project/src/lib-cti/test.h"
...
%}

#ifndef CTI_TYPES_H_
#define CTI_TYPES_H_
#include "cti_const.h"

typedef char FOO[CONST];

typedef struct
{
    char *key;
    void *value;
    int size;
} cti_pair;

The problem is that I can access the cti_pair struct, but can't use FOO (it's not defined) in my python script.

Upvotes: 2

Views: 1071

Answers (1)

Cyrus4ever
Cyrus4ever

Reputation: 81

Ok, just figure out what the problem was. Actually, I used %extend in another part of the interface file. But this keyword can only be used on structures, not on basic typedef (and SWIG does not display any error message if we use %extend the wrong way).

As a matter of fact, FOO was defined. The problem was not related to this at all. Thanks!

Upvotes: 1

Related Questions