问题
I have used swig to do generate java bindings for independent classes. However when I tried to do it for my existing codebase which is quite complex, having calls for STL , OSG and OpenGL. When I am trying to swig it am getting issues. Here is my .i file
/* File : Line.i */
%module Line
%{
#include "Elements/LineFeatureObject.h"
%}
/* Let's just grab the original header file here */
%include "Elements/LineFeatureObject.h
This headers includes several other headers files. Some of them are read by the code while for some it gives the following warnings. Warning 401: Nothing known about base class 'ELEMENTS::ILineAlgebra'. Ignored. These classes are listed in the same location with rest of the classes. So am not sure what is going wrong with just couple of these classes.
Moving on I am able to get _wrap.cxx but when am compiling it am getting the following errors. error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C2144: syntax error : 'void' should be preceded by ';' error C2086: 'int WINGDIAPI' : redefinition C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1152) : see declaration of 'WINGDIAPI' . . .
Have not listed all of them here. Can you help me find way around these errors.
回答1:
SWIG by default only processes the top-level file named by %include
. It does not recurse into additional #include
files. You must explicitly %include
the headers files you wish SWIG to process.
SWIG also does not know anything about STL, but there are some SWIG headers that can add support for STL types like std::string
and std::vector
. STL templates must be explicitly instantiated and given a target language name: Example:
%include <std_string.i>
%include <std_vector.i>
%template(IntVector) std::vector<int>;
SWIG also does not know about Windows types and compiler extensions and can be confused by __stdcall
, __cdecl
, __declspec(dllexport)
, DWORD
, UINT
, etc., but this include helps:
%include <windows.i>
来源:https://stackoverflow.com/questions/16980181/how-to-swig-my-entire-c-code-base-to-java