简体   繁体   中英

How to use SWIG to generate C# on Linux when it can generate correctly on Win7

I am using SWIG 3.0.12 to generate C# wrapper from C++ on Win7. The command is:

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

This work fine on windows. Our C++ and SWIG generated wrapper compiled in Visual Studio, and the compiled dll can be called in C# code.

Now, we need to move C++ and C# code into Debian 9 with gcc and mono. Then what is the correct command to generate wrapper code on Linux?

In the above Win7 command it has a macro "WIN32", I guess this shall not be needed in Linux. The generated wrapper .cxx file on Win7 contains a number of conditional defines that seems for Windwos or GCC, for example:

#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

How can I define correct macros for Linux and gcc?

Furthermore, our DS.i file also has a include related to Windows, I am not sure if we shall also remove that for Linux:

%include <windows.i>
%include <std_string.i>
%include <std_wstring.i>
... ...
swig.exe -c++ -csharp -namespace DS -outdir D:/DS_CSharp/GeneratedSWIG DS.i

The __GNUC__ is automatically defined when build generated code using gcc. This is checked by adding print out in macro defines, eg #warning my messages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM