tags:

views:

43

answers:

1

I am writing a C/C++ extension module for other languages and I am using SWIG to generate the bindings.

I have two questions

  1. Can I include more than 1 header file in the declaration part of the interface file e.g.:

    /* Declarations exposed to wrapper: */

    > %{
    > #define SWIG_FILE_WITH_INIT
    > #include "a.h"
    > #include "b.h"
    > #include "c.h" %}
    
  2. In all of the examples I have seen so far, after the header include declaration (as shown above), the functions declared in the header are then declared again in the interface file. Is this really necessary, as it means there are two copies of the function declarations that need to be maintained.

Note: I can appreciate that some functions/methods declaration may need to be 'decorated' with the 'newobject' declaration so these obviously need to be in the interface file, to avoid memory leaks - however, I would have though that it would be sufficient to include the headers and then ONLY the declarations of the functions/methods that need to be declared with 'newobject' - is this recommended way of doing things?

+1  A: 
  1. Yes ( see http://www.swig.org/Doc1.1/HTML/Library.html )
  2. No ( see http://www.swig.org/tutorial.html ; look for SWIG for the truly lazy )
Yktula
For the 2nd question, the answer seems to be a YES rather than a no (i.e. I CAN be lazy, and just include the headers and not redeclare the function prototypes) - Right?
morpheous
You're interpretation in the comment is correct: you "CAN be lazy, and just include the headers and not redeclare the function prototypes", but the answer to the question ("Is this really necessary", when discussing redeclaring function prototypes) is a no.
Yktula
thanks for the clarification :)
morpheous