![]() |
What is
Swig? 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 compatable 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 verision 1.3.40 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. |
![]() |
Windows 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.
|
Generating the Swig Files Using Included Tools |
Generating
the Swig Files Using Included Tools on Windows.
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 |
Windows Generate the Swig Files
Generate the Swig Files
-c++ This must come first. This means that the source files are C++ not C. -csharp This is the target language. Currently the files are made for C# and may not work with the other options. -I"PATH_TO_RAKNETSOURCE" This option includes the directory for any source and includes if different from the interface file location. -I"SwigInterfaceFiles" This option includes the directory for the interface files. -outdir SwigOutput/SwigCSharpOutput This is where the output files to be included in the target language are placed. -o SwigOutput/CplusDLLIncludes/RakNet_wrap.cxx This is where the file that is included in the DLL project is placed. |
![]() |
Windows Note: There is a directory called DLL_Swig that contains a project that makes the Swig files, builds the DLL, and copies it to the C# sample. The next steps are for making your own project. Creating the Swig DLL
Linux Creating the Swig Dynamic Link Note:
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
successfully.
|
![]() |
Windows C# Project Setup
A C# sample project is included under Samples/Swig. 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. Linux Installing Mono, if it is not Installed Note: 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
A C# sample is included under Samples/Swig/SwigLinux. The DLL file is not included and needs to be copied to /usr/lib as per the earlier instructions. |
![]() |
Limitations
|
![]() |