【问题标题】:How to use SWIG to generate C# on Linux when it can generate correctly on Win7如何在 Linux 上使用 SWIG 在 Win7 上正确生成 C#
【发布时间】:2019-07-15 20:38:06
【问题描述】:

我正在使用 SWIG 3.0.12 在 Win7 上从 C++ 生成 C# 包装器。 命令是:

swig.exe -c++ -csharp -namespace DS -DWIN32 -outdir D:/DS_CSharp/GeneratedSWIG DS.i

这在 Windows 上运行良好。我们的 C++ 和 SWIG 生成的包装器在 Visual Studio 中编译,编译后的 dll 可以在 C# 代码中调用。

现在,我们需要使用 gcc 和 mono 将 C++ 和 C# 代码移动到 Debian 9 中。那么在 Linux 上生成包装器代码的正确命令是什么?

在上面的 Win7 命令中,它有一个宏“WIN32”,我想这在 Linux 中应该不需要。 Win7 上生成的包装器 .cxx 文件包含许多似乎适用于 Windwos 或 GCC 的条件定义,例如:

#ifndef SWIGEXPORT
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
#   if defined(STATIC_LINKED)
#     define SWIGEXPORT
#   else
#     define SWIGEXPORT __declspec(dllexport)
#   endif
# else
#   if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
#     define SWIGEXPORT __attribute__ ((visibility("default")))
#   else
#     define SWIGEXPORT
#   endif
# endif
#endif

如何为 Linux 和 gcc 定义正确的宏?

此外,我们的 DS.i 文件还有一个与 Windows 相关的包含,我不确定我们是否也应该在 Linux 上删除它:

%include <windows.i>
%include <std_string.i>
%include <std_wstring.i>
... ...

【问题讨论】:

    标签: c++ linux debian swig


    【解决方案1】:
    swig.exe -c++ -csharp -namespace DS -outdir D:/DS_CSharp/GeneratedSWIG DS.i
    

    __GNUC__ 是在使用 gcc 构建生成的代码时自动定义的。这通过在宏定义中添加打印输出来检查,例如#警告我的消息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多