| What is
Swig is an application that generates wrapper code for a native DLL to interface with other languages allowing you to use a C/C++ library in one of the supported languages. Currently Swig configuration for RakNet is set up to generate a managed interface that can be used in managed C# in Windows, as well as in Linux with Mono.
Swig generates a CXX and .h file, which exposes interfaces that can be used by the target language. The CXX file is included when building the C++ dll that the target language uses.
Swig also generates files in the target language for inclusion in the project of the target language to interface with the dll. These are added to the project of the target language.
What is Mono?
Mono is a cross platform implementation of the .Net framework. This allows you to compile C# and other .Net code and run them on platforms that originally are not .Net compatible like Linux.
Choices to Make.
You may choose to use the tools with RakNet or start from scratch.
On Windows batch tools are provided make the process easier. These tools are located under the Swig Directory under DependentExtensions. For Linux the tools will use Wget to pull down Swig and install version 2.0.00 if Swig is not installed.
You may also download Swig yourself and compile them by specifying the options manually. In the manual portion the options used will be explained.
-Using DLL_Swig\RakNet.sln solution
Download Swig and Unzip.
Download Swig,Unzip,Make, and Install.
Note: You may be able to install Swig using your favorite package manager, if you can go that route do so. The instructions vary depending on your package manager and distribution. The batch file will attempt to install 1.6, but it is recommended to use the package manager if you are able to.
|Generating the Swig Files Using Included Tools|
the Swig Files Using Included Tools on Windows.
Note: This step on Windows can be skipped if you are using the included DLL_Swig project as it runs the tools on rebuild.
Note: The Linux batch requires Wget,Tar,Make and GCC to be installed, unless swig is already installed. Most of the time Wget,Tar,Make and GCC are already installed.
|Generating the Swig Files Manually|
Generate the Swig Files
Generate the Swig Files
This must come first. This means that the source files are C++ not C.
This is the target language. Currently the files are made for C# and may not work with the other options.
This puts the generated files in the C# namespace RakNet
This option includes the directory for any source and includes if different from the interface file location.
This option includes the directory for the interface files.
This is where the output files to be included in the target language are placed.
This is where the file that is included in the DLL project is placed.
*The below two are used if SQLiteClientLoggerPlugin is used:
Another include directory, the base directory where the SQLite plugin is.
A conditional compilation symbol, defined to include SQLiteClientLoggerPlugin.
|Creating the Swig Wrapped DLL Project|
Note: If you do not plan on using SQLiteClientLoggerPlugin, DependentExtensions\Swig\DLL_Swig\RakNet.sln already contains a DLL project that makes the Swig files, builds the DLL, and copies it to the C# sample. You do not need to run these steps if you use that project. In that case, run the solution, rebuild the project, and goto "Creating the C# project"
Creating the Swig DLL
Creating the Swig Dynamic Link
If you ran the linux batch tool it will have made the dynamic link and
attempted to install it, so you may skip these steps if it ran
|Creating the C# project|
C# Project Setup
A C# sample project is included under DependentExtensions\Swig\SwigWindowsCSharpSample. The DLL file is not included and needs to be copied to the bin/Debug or the bin/Release folder depending on whether or not you are doing a release or debug build. If the DLL_Swig project is used the dll is copied automatically.
Installing Mono, if it is not Installed
Note: Mono greater than version 2.0 is needed for full compatability, earlier versions work with most of RakNet but cause crashes in some of it. You may be able to install Mono using your favorite package manager, if you can go that route do so. The instructions vary depending on your package manager and distribution. Some package manager have different options for the C# compiler. This tutorial assumes gmcs is installed.
C# Project Setup
Note: If you used the included tools and just want to run the sample you may skip this section.
A C# sample is included under DependentExtensions/Swig/SwigLinuxCSharpSample. The DLL file is not included and needs to be copied to /usr/lib as per the earlier instructions. If the tools are used the cs files are automatically copied to the sample directory and there is an attempt by tools to copy the dll to /usr/lib.