{"id":8959,"date":"2017-11-20T14:00:08","date_gmt":"2017-11-20T05:00:08","guid":{"rendered":"http:\/\/www.moonmile.net\/blog\/?p=8959"},"modified":"2017-11-21T11:00:41","modified_gmt":"2017-11-21T02:00:41","slug":"swig-%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6-c-%e3%81%ae%e3%82%af%e3%83%a9%e3%82%b9%e3%82%92-c-%e3%81%a7%e8%aa%ad%e3%81%bf%e8%be%bc%e3%82%80%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.moonmile.net\/blog\/archives\/8959","title":{"rendered":"SWIG \u3092\u4f7f\u3063\u3066 C++ \u306e\u30af\u30e9\u30b9\u3092 C# \u3067\u8aad\u307f\u8fbc\u3080\u65b9\u6cd5"},"content":{"rendered":"<p>FFFTP2 \u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u5316\u306e\u524d\u8abf\u67fb\u3068\u3057\u3066\u3001C++ \u306e\u30af\u30e9\u30b9\u306b\u66f8\u304d\u66ff\u3048\u305f\u3068\u304d\u306b\u3001.NET\u304b\u3089\u547c\u3073\u51fa\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u3060\u308d\u3046\u304b\uff1f\u3068\u3044\u3046\u306e\u3092\u8abf\u3079\u3066\u3044\u307e\u3057\u305f\u3002\u57fa\u672c C# \u304b\u3089 C\/C++ \u3092\u547c\u3073\u51fa\u3059\u3068\u304d\u306f dllimport \u3092\u4f7f\u3046\u8a33\u3067\u3059\u304c\u3001\u3053\u308c\u306f\u300cC\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u300d\u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u3067\u3001C++\u306e\u30af\u30e9\u30b9\u3092\u76f4\u63a5\u547c\u3073\u51fa\u3059\u3053\u3068\u306f\u3057\u3066\u3044\u307e\u305b\u3093\u3002\u306a\u306e\u3067\u3001C++\u306e\u5834\u5408\u306f\u3001\u4e00\u5ea6C\u306e\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u306b\u76f4\u3057\u3066\u547c\u3073\u51fa\u3055\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u3067\u3059\u3088\u306d\u3002OpenCvSharp \u306e\u5834\u5408\u3082\u3001OpenCV \u3092\u547c\u3073\u51fa\u3059\u3068\u304d\u306b\u3001dllimport \u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u3072\u3068\u3064\u3072\u3068\u3064 C \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30b9\u306b\u76f4\u3057\u3066\u7d44\u307f\u66ff\u3048\u3066\u3044\u307e\u3059\u3002\u3053\u3053\u306e\u624b\u9593\u304c\u306a\u3093\u3068\u3082\u8a00\u3048\u306a\u3044\u306e\u3068\u3001\u5c06\u6765\u7684\u306b C++ \u306e\u69cb\u9020\u304c\u5909\u308f\u3063\u305f\u3068\u304d\u306b\u306f\u3053\u306e\u90e8\u5206\u3092\u624b\u4f5c\u696d\u3067\u76f4\u3055\u306a\u3044\u3068\u3044\u3051\u307e\u305b\u3093\u3088\u306d\uff08\u5b9f\u969b OpenCV2 \u304b\u3089 OpenCV3 \u306e\u5909\u63db\u306e\u3068\u304d\u306b\u767a\u751f\u3057\u3066\u3044\u308b\u554f\u984c\u3067\uff09\u3002\u3068\u306a\u308c\u3070\u3001Xamarin.Android \u306e\u30d0\u30a4\u30f3\u30c9\u6a5f\u80fd\u3088\u308d\u3057\u304f\u3001*.jar \u30d5\u30a1\u30a4\u30eb\u304b\u3089\u9069\u5f53\u306a C# \u306e\u30af\u30e9\u30b9\u3092\u5410\u304d\u51fa\u3059\u3088\u3046\u306a\u4ed5\u7d44\u307f\u304c\u6b32\u3057\u3044\u3068\u3053\u308d\u3067\u3059\u3002<\/p>\n<p>\u672c\u5f0f\u306b\u3084\u308b\u306a\u3089\u3070\uff1f CppSharp \u3063\u307d\u3044\u306e\u3067\u3059\u304c https:\/\/github.com\/mono\/CppSharp \u3069\u3046\u3084\u3089\u300c\u68d8\u306e\u9053\u300d\u3060\u305d\u3046\u306a\u306e\u3067\u3001\u3061\u3087\u3063\u3068\u907f\u3051\u3066\u3001SWIG http:\/\/swig.org\/ \u3092\u8a66\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u4ee5\u524d\u3001Python \u304b\u3089 C\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u547c\u3073\u51fa\u3059\u306e\u306b SWIG \u3092\u4f7f\u3046\u8a71\u3092\u3061\u3089\u3063\u3068\u805e\u3044\u305f\u5f8c\u306b\u3001\u305d\u308c\u4ee5\u964d\u8abf\u3079\u3066\u3044\u306a\u304b\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u3069\u3046\u3084\u3089 C++ \u306b\u3082\u5bfe\u5fdc\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>SWIG\u306ewindows\u7248\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9<\/h2>\n<p>Visual Studio 2017 \u3067\u4f5c\u696d\u3092\u3059\u308b\u306e\u3067\u3001windows \u7248\u3092\u843d\u3068\u3057\u307e\u3059\u3002https:\/\/sourceforge.net\/projects\/swig\/files\/ \u306b\u3042\u308b swigwin \u306e\u307b\u3046\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u5c55\u958b\u3059\u308b\u3068\u3001swig.exe \u3068\u5909\u63db\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u304c\u3042\u308b Lib\/*.i \u7b49\u304c\u3067\u3066\u304d\u307e\u3059\u3002<\/p>\n<p>\u3053\u3053\u3067\u306f C\/C++ \u3092 C# \u306b\u5909\u63db\u3059\u308b\u306e\u3067\u3001Lib\/charp\/*.i \u304c\u4f7f\u308f\u308c\u307e\u3059\u306d\u3002<\/p>\n<p><a href=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2017\/11\/dworkblogimage20171120_01org.jpg\"><img decoding=\"async\" src=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2017\/11\/dworkblogimage20171120_01thum.jpg\" border=\"0\" \/><\/a><\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<p>\u30b5\u30f3\u30d7\u30eb\u306f http:\/\/github.com\/moonmile\/helloswig \u306b\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>&#8211; helloswig : Visual Studio \u3067\u4f5c\u3063\u305f C++ \u306e DLL \u30d7\u30ed\u30b8\u30a7\u30af\u30c8<br \/>\n&#8211; hello : DLL \u3092\u5229\u7528\u3059\u308b C# \u30d7\u30ed\u30b8\u30a7\u30af\u30c8<\/p>\n<p>hello \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306f\u53ef\u642c\u6027\u3092\u78ba\u8a8d\u3059\u308b\u305f\u3081\u306b\u3001.NET Core \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u4f5c\u3063\u3066\u3042\u308a\u307e\u3059\u3002Windows \u4e0a\u306e\u307f\u3067\u52d5\u304b\u3059\u5834\u5408\u3084 Linux \u4e0a\u3067 mono \u3092\u4f7f\u3046\u5834\u5408\u306f .NET Framework \u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u3082\u53ef\u80fd\u3067\u3059\u3002Windows \u4e0a\u306e\u307f\u3067\u52d5\u4f5c\u3092\u8003\u3048\u308b\u306a\u3089\u3070\u3001DLL \u306f MFC DLL \u3067\u3082\u52d5\u4f5c\u3057\u307e\u3059\u3002<\/p>\n<h2>helloswig \u30d7\u30ed\u30b8\u30a7\u30af\u30c8<\/h2>\n<p>helloswig.cpp \u306b\u5b9f\u4f53\u3092\u5b9a\u7fa9\u3057\u307e\u3059\u3002\u3053\u308c\u306f DLL \u5185\u3067\u52d5\u304f\u30b3\u30fc\u30c9\u3067\u3059\u306d\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n#include &quot;stdafx.h&quot;\r\n#include &quot;helloswig.h&quot;\r\n\r\nHello::Hello() : _name(&quot;&quot;) {}\r\n\r\nvoid Hello::SetName(const char *name ) {\r\n\t_name = std::string(name);\r\n}\r\n\r\nconst char * Hello::GetName() {\r\n\treturn _name.c_str();\r\n}\r\n\r\nint Hello::Add(int x, int y) { return x + y; }\r\nint Hello::Mul(int x, int y) { return x * y; }\r\n<\/pre>\n<p>helloswig.h \u306f\u5916\u90e8\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3067\u3059\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n#pragma once\r\n#include &lt;string&gt;\r\nclass Hello\r\n{\r\nprivate:\r\n\tstd::string _name;\r\npublic:\r\n\tHello();\r\n\tvoid SetName(const char *name);\r\n\tconst char *GetName();\r\n\tint Add(int x, int y);\r\n\tint Mul(int x, int y);\r\n};\r\n<\/pre>\n<p>SWIG \u306e\u5834\u5408\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u30d8\u30c3\u30c0\u30d5\u30a1\u30a4\u30eb\u306e\u5168\u3066\u306e\u30af\u30e9\u30b9\uff06\u5168\u3066\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u516c\u958b\u5bfe\u8c61\u306b\u306a\u308b\u306e\u3067\u3001\u3053\u306e\u90e8\u5206\u306f\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u7528\u306e\u3082\u306e\u3092\u4f5c\u3063\u305f\u307b\u3046\u304c\u3088\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u5f8c\u3001\u7570\u306a\u308b\u74b0\u5883\u3067\u30d3\u30eb\u30c9\u3059\u308b\u3053\u3068\u3092\u8003\u3048\u308b\u3068 windows.h \u306a\u3069\u306e\u8aad\u307f\u8fbc\u307f\u306f\u3067\u304d\u306a\u3044\u306e\u3067\u3001\u7d50\u69cb\u300c\u7dba\u9e97\u306a\u30d8\u30c3\u30c0\u30d5\u30a1\u30a4\u30eb\u300d\u304c\u5fc5\u8981\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n#pragma once\r\n#include &lt;string&gt;\r\nclass Hello\r\n{\r\nprivate:\r\n\tstd::string _name;\r\npublic:\r\n\tHello();\r\n\tvoid SetName(const char *name);\r\n\tconst char *GetName();\r\n\tint Add(int x, int y);\r\n\tint Mul(int x, int y);\r\n};\r\n<\/pre>\n<p>helloswig.i \u306f\u3001SWIG \u3067\u53d6\u308a\u8fbc\u3080\u305f\u3081\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3067\u3059\u3002%module \u306e\u90e8\u5206\u304c DLL \u306e\u540d\u524d\uff08C#\u5074\u306e dllimport \u3067\u6307\u5b9a\u3055\u308c\u307e\u3059\uff09\u3002%include \u304c\u516c\u958b\u3059\u308b\u305f\u3081\u306e C++ \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30b9\u3067\u3059\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/* File : helloswig.i *\/\r\n%module helloswig\r\n\r\n%{\r\n#include &quot;helloswig.h&quot;\r\n%}\r\n\r\n\/* Let's just grab the original header file here *\/\r\n%include &quot;helloswig.h&quot;\r\n<\/pre>\n<p>*.i \u30d5\u30a1\u30a4\u30eb\u306f\u305d\u306e\u307e\u307e\u3067\u306f\u30d3\u30eb\u30c9\u3067\u304d\u306a\u3044\u306e\u3067\u3001swig.exe \u3092\u547c\u3073\u51fa\u3059\u3088\u3046\u306b\u3057\u307e\u3059\u3002<br \/>\n\u30d5\u30a1\u30a4\u30eb\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3067\u3001\u300c\u30ab\u30b9\u30bf\u30e0\u30d3\u30eb\u30c9\u30c4\u30fc\u30eb\u300d\u3092\u6307\u5b9a\u3057\u3066\u3001<\/p>\n<p><a href=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2017\/11\/dworkblogimage20171120_02org.jpg\"><img decoding=\"async\" src=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2017\/11\/dworkblogimage20171120_02thum.jpg\" border=\"0\" \/><\/a><\/p>\n<p>\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u3068\u51fa\u529b\u30d5\u30a1\u30a4\u30eb\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2017\/11\/dworkblogimage20171120_03org.jpg\"><img decoding=\"async\" src=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2017\/11\/dworkblogimage20171120_03thum.jpg\" border=\"0\" \/><\/a><\/p>\n<p>swig.exe \u306e\u30d1\u30b9\u306f\u74b0\u5883\u306b\u3088\u3063\u3066\u5408\u308f\u305b\u3066\u304f\u3060\u3055\u3044\u3002swig.exe \u306e\u3042\u308b\u30d5\u30a9\u30eb\u30c0\u306e Lib \u30d5\u30a9\u30eb\u30c0\u30fc\u304b\u3089\u8a2d\u5b9a\u6e08\u307f\u306e *.i \u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\u3088\u3046\u3067\u3059\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\necho Invoking SWIG...\r\necho on\r\n..\\swig.exe -c++ -csharp &quot;%(FullPath)&quot;\r\n%40echo off\r\n<\/pre>\n<p>\u4e00\u5ea6\u3001\u30d3\u30eb\u30c9\u3092\u901a\u3059\u3068 helloswig_wrap.cxx \u306e\u3088\u3046\u306a\u30e9\u30c3\u30d7\u3092\u3057\u305f\u30af\u30e9\u30b9\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002\u4e2d\u8eab\u3092\u898b\u308b\u3068\u89e3\u308b\u306e\u3067\u3059\u304c\u3001\u4e00\u5ea6 C \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u306b\u76f4\u3057\u3066\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n...\r\n#ifdef __cplusplus\r\nextern &amp;quot;C&amp;quot; {\r\n#endif\r\n\r\nSWIGEXPORT void * SWIGSTDCALL CSharp_new_Hello() {\r\n  void * jresult ;\r\n  Hello *result = 0 ;\r\n  \r\n  result = (Hello *)new Hello();\r\n  jresult = (void *)result; \r\n  return jresult;\r\n}\r\n\r\n\r\nSWIGEXPORT void SWIGSTDCALL CSharp_Hello_SetName(void * jarg1, char * jarg2) {\r\n  Hello *arg1 = (Hello *) 0 ;\r\n  char *arg2 = (char *) 0 ;\r\n  \r\n  arg1 = (Hello *)jarg1; \r\n  arg2 = (char *)jarg2; \r\n  (arg1)-&gt;SetName((char const *)arg2);\r\n}\r\n...\r\n<\/pre>\n<p>\u3053\u308c\u3068\u540c\u6642\u306b\u3001helloswigPINVOKE.cs \u306e\u3088\u3046\u306a C# \u5074\u3067\u30a4\u30f3\u30dd\u30fc\u30c8\u3059\u308b\u30af\u30e9\u30b9\u304c\u4f5c\u3089\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n...\r\n  &#x5B;global::System.Runtime.InteropServices.DllImport(&quot;helloswig&quot;, EntryPoint=&quot;CSharp_new_Hello&quot;)]\r\n  public static extern global::System.IntPtr new_Hello();\r\n\r\n  &#x5B;global::System.Runtime.InteropServices.DllImport(&quot;helloswig&quot;, EntryPoint=&quot;CSharp_Hello_SetName&quot;)]\r\n  public static extern void Hello_SetName(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2);\r\n\r\n  &#x5B;global::System.Runtime.InteropServices.DllImport(&quot;helloswig&quot;, EntryPoint=&quot;CSharp_Hello_GetName&quot;)]\r\n  public static extern string Hello_GetName(global::System.Runtime.InteropServices.HandleRef jarg1);\r\n...\r\n<\/pre>\n<h2>hello \u30d7\u30ed\u30b8\u30a7\u30af\u30c8<\/h2>\n<p>C# \u5074\u306f\u3001\u3082\u3068\u3082\u3068\u4f55\u3082\u306a\u3044\u30af\u30e9\u30b9\u3067\u3059\u304c\u3001C++ \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\uff08helloswig\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\uff09<br \/>\n\u3067\u4f5c\u6210\u3057\u305f *.cs \u30d5\u30a1\u30a4\u30eb\uff08Hello.cs, helloswig.cs, helloswigPINVOKE.cs\uff09\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p>Program.cs<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nusing System;\r\n\r\nnamespace hello\r\n{\r\n    class Program\r\n    {\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            Console.WriteLine(&quot;Hello swig world.&quot;);\r\n\r\n            var hello = new Hello();\r\n            hello.SetName(&quot;Tomoaki Masuda&quot;);\r\n            var name = hello.GetName();\r\n            Console.WriteLine($&quot;name: {name}&quot;);\r\n\r\n            hello.SetName(&quot;Jhon doe&quot;);\r\n            name = hello.GetName();\r\n            Console.WriteLine($&quot;name: {name}&quot;);\r\n\r\n            int x = 10;\r\n            int y = 20;\r\n            Console.WriteLine($&quot;{x} + {y} = {hello.Add(x, y)}&quot;);\r\n            Console.WriteLine($&quot;{x} * {y} = {hello.Mul(x, y)}&quot;);\r\n\r\n            Console.WriteLine(&quot;end&quot;);\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>C# \u5074\u306e main \u30b3\u30fc\u30c9\u306f\u3001\u901a\u5e38\u306b C# \u306e\u30b3\u30fc\u30c9\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\nSWIG \u3067\u51fa\u529b\u3057\u305f C# \u30b3\u30fc\u30c9\u3092\u3044\u3061\u3044\u3061\u8ffd\u52a0\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u306e\u3067\u3059\u304c\u3001\u307e\u3042\u305d\u306e\u3042\u305f\u308a\u306f\u30d0\u30c3\u30c1\u51e6\u7406\u3092\u3059\u308b\u3068\u304b\u30ea\u30f3\u30af\u3067\u89e3\u6c7a\u3059\u308b\u3068\u304b\u3067\u304d\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n<h2>\u30d3\u30eb\u30c9\u3057\u3066\u5b9f\u884c\u3059\u308b<\/h2>\n<p>.NET Core \u3067\u30a4\u30f3\u30dd\u30fc\u30c8\u3067\u304d\u308b DLL \u306f x64 \u306e\u307f\u306a\u306e\u3067\u3001\u305d\u306e\u3042\u305f\u308a\u3092\u6ce8\u610f\u3057\u306a\u304c\u3089\u5b9f\u884c\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n<ol>\n<li>C++\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\uff08helloswig\uff09\u3092 x64\/Debug \u3042\u308b\u3044\u306f x64\/Release \u3067\u30d3\u30eb\u30c9.<\/li>\n<li>C#\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\uff08hello\uff09\u3092\u30d3\u30eb\u30c9\u3002.NET Core \u306a\u306e\u3067\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u304b\u3089 dotnet build \u3067\u3082 ok \u3067\u3059\u3002<\/li>\n<li>\u4f5c\u6210\u3057\u305f dll \u3092 .NET Core \u306e\u5b9f\u884c\u30d5\u30a1\u30a4\u30eb\u306e\u5834\u6240\u306b\u30b3\u30d4\u30fc\uff08bin\/Debug\/netcoreapp2.0\/ \u306b\u30b3\u30d4\u30fc\uff09<\/li>\n<li>dotnet run \u3059\u308b\u3002<\/li>\n<\/ol>\n<p><a href=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2017\/11\/dworkblogimage20171120_03org-1.jpg\"><img decoding=\"async\" src=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2017\/11\/dworkblogimage20171120_03thum-1.jpg\" border=\"0\" \/><\/a><\/p>\n<h2>Ubuntu\u74b0\u5883\u3067\u30d3\u30eb\u30c9\u5b9f\u884c\u3059\u308b<\/h2>\n<p>\u3055\u3066\u3001Windows \u74b0\u5883\u3067\u52d5\u4f5c\u304c\u78ba\u8a8d\u3067\u304d\u305f\u306e\u3067\u3001Ubuntu\u306b\u6301\u3063\u3066\u884c\u3063\u3066\u52d5\u304b\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u30b3\u30fc\u30c9\u3092\u3054\u3063\u305d\u308a\u3068 Ubuntu \u306b\u6301\u3063\u3066\u884c\u3063\u3066\u3001\u5171\u6709\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u305f\u3081\u306e Makefile \u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nall: libhelloswig.so\r\n\r\nlibhelloswig.so: helloswig.o\r\n\tg++ -sharad helloswig.o helloswig_wrap.o -o libhelloswig.so\r\nhelloswig.o: helloswig.cpp\r\n\tg++ -c helloswig.cpp\r\nhelloswig_wrap.o: helloswig_wrap.cpp\r\n\tg++ -c helloswig_wrap.cpp\r\n<\/pre>\n<p>\u3042\u307e\u308a\u306b\u4e45\u3005\u3060\u3063\u305f\u306e\u3067\u3001\u30d9\u30bf\u306a makefile \u3067\u3059\u304c\u3001\u307e\u3042\u3053\u308c\u3067 libhelloswig.so \u304c\u30d3\u30eb\u30c9\u3067\u304d\u307e\u3059\u3002<br \/>\n\u672c\u6765\u306a\u3089\u3070\u3001ubuntu \u4e0a\u3067 swig \u3092\u52d5\u304b\u3057\u3066\u30e9\u30c3\u30d7\u3059\u308b C# \u30b3\u30fc\u30c9\u3092\u5410\u304d\u51fa\u3059\u3068\u3053\u308d\u3067\u3059\u304c\u3001\u65e2\u306b Windows \u4e0a\u3067\u4f5c\u6210\u3057\u3066\u3044\u308b\u306e\u3067\u518d\u5229\u7528\u3057\u307e\u3059\u3002\u3061\u306a\u307f\u306b\u3001ubuntu \u4e0a\u3067\u306f\u300csudo apt-get install swig\u300d\u3067 SWIG \u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p>libhelloswig.so \u30d5\u30a1\u30a4\u30eb\u3092\u6307\u5b9a\u3059\u308b\u305f\u3081\u306b LD_LIBRARY_PATH \u3092\u8a2d\u5b9a\u3057\u3066 dotnet run \u3057\u307e\u3059\u3002<\/p>\n<p>export LD_LIBRARY_PATH=~\/swig\/helloswig<\/p>\n<p><a href=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2017\/11\/dworkblogimage20171120_04org.jpg\"><img decoding=\"async\" src=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2017\/11\/dworkblogimage20171120_04thum.jpg\" border=\"0\" \/><\/a><\/p>\n<p>\u3053\u3053\u3067\u3001\u3061\u3087\u3063\u3068\u9762\u767d\u3044\u306e\u306f .NET Core \u3067 DllImport \u3092\u4f7f\u3046\u3068\u3001Windows \u306e\u5834\u5408\u306f\u300chelloswig.dll\u300d\u3092\u53c2\u7167\u3057\u3001Ubuntu \u4e0a\u3067\u306f\u300clibhelloswig.so\u300d\u3092\u53c2\u7167\u3059\u308b\u3068\u3053\u308d\u3067\u3059\u306d\u3002\u3053\u3093\u305f\u3081\u3001Windows \u306e SWIG \u3067\u51fa\u529b\u3057\u305f C# \u30e9\u30c3\u30d1\u30fc\u304c\u305d\u306e\u307e\u307e Ubuntu \u3067\u3082\u4f7f\u3048\u307e\u3059\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n  &#x5B;global::System.Runtime.InteropServices.DllImport(&quot;helloswig&quot;, EntryPoint=&quot;CSharp_new_Hello&quot;)]\r\n  public static extern global::System.IntPtr new_Hello();\r\n<\/pre>\n<p>\u5171\u6709\u30d5\u30a1\u30a4\u30eb\u306b lib \u3092\u4ed8\u3051\u3066\u304a\u304f\u3068\u4fbf\u5229\u3067\u3059\u3002<\/p>\n<h2>Raspberry Pi\u4e0a\u3067\u5b9f\u884c\u3059\u308b<\/h2>\n<p>\u3067\u306f\u3001\u30e9\u30ba\u30d1\u30a4\u4e0a\u3067\u52d5\u304b\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002Raspberry Pi\u3067\u306f\u3001.NET Core \u304c\u30d3\u30eb\u30c9\u3067\u304d\u306a\u3044\u306e\u3067\u3042\u3089\u304b\u3058\u3081 Windows \u5074\u3067 C# \u30b3\u30fc\u30c9\u3092\u30d3\u30eb\u30c9\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p>dotnet publish -r linux-arm<\/p>\n<p>C++ \u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306fRaspberry Pi\u4e0a\u3067 make \u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2017\/11\/dworkblogimage20171120_06org.jpg\"><img decoding=\"async\" src=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2017\/11\/dworkblogimage20171120_06thum.jpg\" border=\"0\" \/><\/a><\/p>\n<p>\u3053\u308c\u3067\u3001<\/p>\n<p>&#8211; Windows<br \/>\n&#8211; Ubuntu<br \/>\n&#8211; Raspberry Pi<\/p>\n<p>\u306e3\u3064\u306e\u74b0\u5883\u3067\u3001.NET Core + SWIG + C++\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u540c\u3058\u30bd\u30fc\u30b9\u3067\u52d5\u4f5c\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<h2>SWIG\u306e\u96e3\u70b9<\/h2>\n<p>SWIG\u81ea\u4f53\u306f\u3001C# \u3078\u306e\u30b3\u30f3\u30d0\u30fc\u30c8\u3060\u3051\u3067\u306a\u304f\u3001Java\u3084Python\u306a\u3069\u3078\u306e\u30b3\u30f3\u30d0\u30fc\u30c8\u304c\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u8272\u3005\u306a\u8a00\u8a9e\u3067\u6d3b\u7528\u304c\u3067\u304d\u307e\u3059\u3002\u307e\u3042\u3001\u5c0f\u3055\u306a\u81ea\u524d\u306e C\/C++ \u30e9\u30a4\u30d6\u30e9\u30ea\u3092 Python \u306a\u3069\u3067\u4f7f\u3046\u5206\u306b\u306f\u3053\u308c\u3067\u3044\u3051\u305d\u3046\u306a\u6c17\u304c\u3059\u308b\u306e\u3067\u3059\u304c\u3001Windows\u4e0a\u306e\u8907\u96d1\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30b3\u30f3\u30d0\u30fc\u30c8\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u96e3\u3057\u305d\u3046\u306a\u70b9\u304c\u3044\u304f\u3064\u304b\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>&#8211; Windows.h \u306a\u3069\u306e Unix \u7cfb\u306b\u306a\u3044\u30a4\u30f3\u30af\u30eb\u30fc\u30c9\u30d5\u30a1\u30a4\u30eb\u306f\u8aad\u307f\u8fbc\u3081\u306a\u3044<br \/>\n&#8211; LPCTSTR \u306a\u3069\u306e\u5b9a\u7fa9\u304c\u8aad\u307f\u8fbc\u3081\u306a\u3044\uff08\u5225\u9014\u5b9a\u7fa9\u304c\u5fc5\u8981\uff09<br \/>\n&#8211; \u6587\u5b57\u5217\u7cfb\u306e\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u306f const char * \u304b wchar_t \u306b\u9650\u3089\u308c\u308b\uff1f<\/p>\n<p>\u6700\u5f8c\u306e\u3072\u3068\u3064\u306f\u3001std_string.i \u3084 std_wstring.i \u306e\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u306f\u3042\u308b\u306e\u3067\u3059\u304c\u3001SWIGTYPE_p_std__string.cs \u3084 SWIGTYPE_p_wchar_t.cs \u306e\u3088\u3046\u306a\u72ec\u81ea\u306a\u30af\u30e9\u30b9\u304c\u4f5c\u3089\u308c\u308b\u306e\u3067\u3061\u3087\u3063\u3068\u9055\u3046\u611f\u3058\u306a\u3093\u3067\u3059\u3088\u306d\u3002\u305f\u3060\u3057\u3001const char * \u306f string \u306b\u5909\u63db\u3055\u308c\u308b\u306e\u3067\u3001dllimport \u306e\u4ed5\u7d44\u307f\u306e\u307e\u307e\u306e\u3088\u3046\u3067\u3059\u3002\u305f\u3060\u3057\u3001\u3053\u306e\u3042\u305f\u308a\u306f\u72ec\u81ea\u306b *.i \u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u308c\u3070\u3088\u3044\u306e\u3067\u3001\u30d4\u30f3\u30dd\u30a4\u30f3\u30c8\u3067 std::string \u304b\u3089 string \u306b\u5909\u63db\u3059\u308b\u3068\u304b\u3001std::wstring \u304b\u3089\u30b3\u30fc\u30c9\u5909\u63db\u3059\u308b\u3068\u304b\u306f\u3067\u304d\u305d\u3046\u306a\u611f\u3058\u306a\u306e\u3067\u3059\u304c\u3002\u3053\u306e\u3042\u305f\u308a\u306f\u5225\u9014\u8abf\u67fb\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>FFFTP2 \u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u5316\u306e\u524d\u8abf\u67fb\u3068\u3057\u3066\u3001C++ \u306e\u30af\u30e9\u30b9\u306b\u66f8\u304d\u66ff\u3048\u305f\u3068\u304d\u306b\u3001.NET\u304b\u3089\u547c\u3073\u51fa\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u3060\u308d\u3046\u304b\uff1f\u3068\u3044\u3046\u306e\u3092\u8abf\u3079\u3066\u3044\u307e\u3057\u305f\u3002\u57fa\u672c C# \u304b\u3089 C\/C++ \u3092\u547c\u3073\u51fa\u3059\u3068\u304d\u306f dllimport \u3092\u4f7f &hellip; <a href=\"https:\/\/www.moonmile.net\/blog\/archives\/8959\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,23,22],"tags":[],"class_list":["post-8959","post","type-post","status-publish","format-standard","hentry","category-dev","category-csharp","category-c"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/8959","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/comments?post=8959"}],"version-history":[{"count":2,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/8959\/revisions"}],"predecessor-version":[{"id":8961,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/8959\/revisions\/8961"}],"wp:attachment":[{"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media?parent=8959"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/categories?post=8959"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/tags?post=8959"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}