как включить std_string.i с помощью swig c ++ для c # - PullRequest
1 голос
/ 22 октября 2019

Я попытался выполнить Swig для преобразования кода C ++ в C #. Я заставил код учебника следовать swig-tutorial . На этапах сборки его не удалось собрать. Я думаю, что это не включенное свойство.

Как его включить?

следующий код является моим учебным кодом.

example.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);

example.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";
 }

runme.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’
....

...