admin管理员组

文章数量:1334887

I have several c++ files & classes under different namespaces that are compiled to the same dll and I want to create corresponding C# API via SWIG interfaces.FileCPP1:

namespace First
{
    class MyClass1 {
    public:
        MyClass1() = default;
        void HelloWorld(const std::string& msg) { cout << "Hello World!" << msg << endl;}
    };
}

FileCPP2:

namespace Second {
    class MyClass2 {
    public:
      MyClass2() = default;
      void HelloWorldAgain(const std::string& msg) { cout << "Hello World again!" << msg << endl;}
     };
}

I tried to do: MyClass1.i file:

%include "std_string.i"
%typemap(csclassmodifiers) First::MyClass1
namespace First {
    class MyClass1 {
      MyClass1();
      void HelloWorld(const std::string& msg);
    };
}

build line: swig.exe -c++ -csharp -DSWIG2_CSHARP -outdir CSFolder -namespace First -module Base

MyClass2.i file:

%include "std_string.i"
%typemap(csclassmodifiers) Second::MyClass2
namespace Second{
    class MyClass2 {
      MyClass2();
      void HelloWorldAgain(const std::string& msg);
    };
}

build line: swig.exe -c++ -csharp -DSWIG2_CSHARP -outdir CSFolder -namespace Second -module Base

Base.i file:

%module Base

%include "MyClass1.i"
%include "MyClass2.i"

build line:

swig.exe -c++ -csharp -DSWIG2_CSHARP -outdir CSFolder

I expect to get in BasePINVOKE.cs file that contains invoke methods from both MyCalss1 and MyClass2, but after build I get randomly only one of those classes invoke methods. All other files are generated as expected. The same happens when I replace "include" with "import". Some ideas what I do wrong?

Try to create SWIG interface of several ".i" that are belong to same dll and different namespace in each file.

本文标签: Build several SWIG interface files under same moduleStack Overflow