【发布时间】: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>
... ...
【问题讨论】: