首页 > 解决方案 > 如何将 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’
....

标签: c#linuxswig

解决方案


推荐阅读