Bibliotecas precompiladas SWIG

I've received a set of 3rd party .lib files and a single .h file which I want to wrap using TRAGO so I can use in another language. All SWIG's examples are with the C\C++ source code, but in my case I don't have the source code.
What should I do different to create the wrapper?

preguntado el 31 de enero de 12 a las 08:01

1 Respuestas

While the SWIG examples may include definitions (source code) to allow the reader to compile and try them, you will notice that all examples of interface files (.i) only contain declarations (what you typically find in a header file), which is all SWIG needs to create a wrapper.

The normal way of writing an interface file goes like this:

/* File : example.i */
%module example
%{
/* This block will end up verbatim in the generated wrapper - include your header
 * so that the wrapper will have access to its definitions 
 */
#include "your_header.h"
%}

/* The definitions in this part are used to generate the wrapper.
 * Copy the definitions you want to export to the other language from the header
 * and put them here 
 */

 extern double variable_from_header;
 extern int    function_from_header(int);

If your header file is simple and you want to export cada definition in it, you might get away with an interface file that looks like this:

/* File : example.i */
%module example
%{
#include "your_header.h"
%}

%include "your_header.h"

Note la %include directive which instructs SWIG to parse the included file as if it were part of the interface definition file. See also Sección 5.7 of the manual that discusses this approach.

Once you have your wrapper, you link it with the lib as you would link the objects created from the source code in the examples.

Respondido el 31 de enero de 12 a las 13:01

Even if you don't have the header file you can still use the first method if you know the declarations of the functions involved - Flexo

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.