问题描述
我使用 swig 为独立类生成 java 绑定.但是,当我尝试为我现有的非常复杂的代码库执行此操作时,需要调用 STL、OSG 和 OpenGL.当我尝试大口喝水时,它出现了问题.这是我的 .i 文件
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
这个头文件包括其他几个头文件.其中一些是由代码读取的,而对于一些则给出以下警告.警告 401:对基类 'ELEMENTS::ILineAlgebra' 一无所知.忽略.这些类与其余类列在同一位置.所以我不确定这几个类出了什么问题.
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.
继续前进,我能够获得 _wrap.cxx,但是在编译它时出现以下错误.错误 C4430:缺少类型说明符 - 假定为 int.注意:C++ 不支持 default-int错误 C2144:语法错误:void"应以;"开头错误 C2086:int WINGDIAPI":重新定义C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1152) :参见WINGDIAPI"的声明...
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-interror 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.
推荐答案
SWIG 默认只处理由 %include
命名的顶级文件.它不会递归到额外的 #include
文件中.您必须明确%include
您希望 SWIG 处理的头文件.
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 也对 STL 一无所知,但有一些 SWIG 标头可以添加对 STL 类型的支持,例如 std::string
和 std::vector
.STL 模板必须显式实例化并给出目标语言名称:示例:
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 也不知道 Windows 类型和编译器扩展,可能会被 __stdcall
、__cdecl
、__declspec(dllexport)
、DWORD
、UINT
等,但这包括帮助:
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>
这篇关于如何将我的整个 C++ 代码库 SWIG 到 Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!