带有 SwigType 的 Csharp Swig 文件

问题描述 投票:0回答:1

我有一个 CPP 项目并尝试使用 Swig 创建 CSharp API。

创建了一个interface.i文件来包装所有头文件。编译文件会生成 .cs 文件和一些带有 SWIGTYPE_p_ 模式的文件......

这些文件 SWIGTYPE_p_ 有什么用...我可以删除这些文件并在构建中仅包含 .cs 文件吗?

观察到很少有 SWIGTYPE_p... 文件没有在之前生成的位置生成。我最近没有做任何代码更改,也不知道去哪里看。

下面是我的示例 .i 文件

// Swig interface file for C# wrapeer for c++ dll
//export module CPP_interface;

% module cppwrappername
% include <std_common.i>
% include <typemaps.i>
% include <std_string.i>
% include <std_wstring.i>
% include <std_vector.i>
% include <std_map.i>
% include <std_pair.i>
% include <windows.i>

using namespace std;

#define unix

% apply char[] { const unsigned char*};

namespace std {
    % apply const string& { string& };
};


#include <pthread.h>
#include <semaphore.h>
% apply sem_t* { Semaphore };

% {
#include <limits.h>
#include <float.h>
#include <string>
#include <iostream>
#include <sstream>
#include <semaphore.h>
#include <pthread.h>
#include <locale>


#include <emperror.h>
#include <empmessage.h>


%}

% ignore  operator<<;
% ignore  operator=;
% ignore  operator==;
//%include "windows.h"

% include "emperror.h"
% include "empmessage.h"

未生成 SWIGTYPE_p_emperror.cs 文件。有什么指示可以看吗?我是 SWIG 新手

c++ swig
1个回答
0
投票

这些文件用于将 c++ 的包装类转换为 c# 的部分类。

参考例如。到: https://www.swig.org/Doc3.0/CSharp.html

20.8.6 将包装类转换为部分类

其他类型转换也是通过将它们放入这些包装类中来进行的,例如数组或 int。

“默认包装将数组视为指针,并因此生成简单类型包装类,例如包装 C 类型 int [] 或 int * 时的 SWIGTYPE_p_int。这给出了对底层非托管代码的相当有限的使用以及最实用的方法使用数组是通过以下三种方法之一进行增强或自定义;即 SWIG C 数组库、P/Invoke 默认数组编组或固定数组。”

© www.soinside.com 2019 - 2024. All rights reserved.