c# - 如何将 std_string.i 与 swig c++ 包含到 c#
问题描述
我尝试执行 swig 将 c++ 代码转换为 c#。我使教程代码遵循swig-tutorial。在构建步骤中,它无法构建。我认为它不包括在内。
我怎样才能包括它?
以下代码是我的教程代码。
例子.i
%module example
%include <std_string.i>
%{
using namespace std;
int my_mod(int x, int y);
string getstring(string str);
%}
int my_mod(int x, int y);
string getstring(string str);
例子.cpp
#include <string>
using namespace std;
double My_variable = 3.0;
int my_mod(int x, int y) {
return (x%y);
}
string getstring(string str)
{
return str+" mine";
}
运行me.cs
using System;
public class runme {
static void Main() {
// Console.WriteLine(example.My_variable);
// Console.WriteLine(example.fact(5));
int i =example.my_mod(10,3);
Console.WriteLine("result " + i);
Console.WriteLine(example.getstring("mygirl"));
}
}
如下所示的错误消息。
example_wrap.c: In function ‘void CSharp_std_set(void*)’:
example_wrap.c:292:18: error: expected ‘=’ before ‘;’ token
namespace arg1 ;
^
example_wrap.c:292:18: error: expected identifier before ‘;’ token
example_wrap.c:293:13: error: expected identifier before ‘*’ token
namespace *argp1 ;
^
example_wrap.c:293:14: error: ‘argp1’ was not declared in this scope
namespace *argp1 ;
^~~~~
example_wrap.c:293:14: note: suggested alternative: ‘jarg1’
namespace *argp1 ;
^~~~~
jarg1
example_wrap.c:295:12: error: expected primary-expression before ‘namespace’
argp1 = (namespace *)jarg1;
^~~~~~~~~
example_wrap.c:295:12: error: expected ‘)’ before ‘namespace’
....
解决方案
推荐阅读
- python - 无法在python上读取文件
- mysql - 如何在case语句中添加东西
- entity-framework-core - Entity Framework Core 3.1 代码优先唯一约束不起作用
- storage - OpenStack Block Storage 无法创建 LVM 物理卷
- html - 将文本或三角形放置在 div 的右上角
- android - 关于 Room DB 中的关系,我应该采用哪种方法?
- javascript - 几秒钟后出现最大调用堆栈大小超出错误。这个js代码有什么问题
- r - read.fwf 不会读取固定宽度文件中的所有行
- android - Google Sign 无法与 signed.apk 一起使用
- javascript - Vue.js:vue.config.js 中的选项无效:不允许使用“插件”