swigtutorial.html 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html><head><title>Swig Tool Based Tutorial</title>
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  4. <link href="RaknetManual.css" rel="stylesheet" type="text/css">
  5. <meta name="title" content="RakNet - Advanced multiplayer game networking API">
  6. <meta http-equiv="content-type" content="text/html; charset=utf-8">
  7. </head>
  8. <body leftmargin="0" topmargin="0" style="background-color: rgb(255, 255, 255);" alink="#003399" link="#003399" marginheight="0" marginwidth="0" vlink="#003399">
  9. <img src="RakNet_Icon_Final-copy.jpg" alt="Oculus VR, Inc." height="150" width="150"><br>
  10. <br>
  11. <br>
  12. <table border="0" width="100%">
  13. <tbody>
  14. <tr>
  15. <td class="RakNetWhiteHeader" bgcolor="#2c5d92"><img src="spacer.gif" height="1" width="8">Overview</td>
  16. </tr>
  17. </tbody>
  18. </table>
  19. <table border="0" cellpadding="10" cellspacing="0" width="100%">
  20. <tbody>
  21. <tr>
  22. <td> <span class="RakNetBlueHeader">What is
  23. Swig?</span><br>
  24. <br>
  25. Swig is an application that generates wrapper code for a native DLL to
  26. interface with other languages allowing you to use a C/C++ library in
  27. one of the supported languages. Currently Swig configuration for RakNet
  28. is set up to generate a managed interface that can be used in managed
  29. C# in Windows, as well as in Linux with Mono.<br>
  30. <br>
  31. Swig generates a CXX and .h file, which exposes interfaces that can be
  32. used by the target language. The CXX file is included when building the
  33. C++ dll that the target language&nbsp; uses.<br>
  34. <br>
  35. Swig also generates files in the target language for inclusion in the
  36. project of the target language to interface with the dll. These are
  37. added to the project of the target language.<br>
  38. <br>
  39. <span class="RakNetBlueHeader">What is Mono?<br>
  40. <br>
  41. </span>Mono is a cross platform implementation of the .Net
  42. framework. This allows you to compile C# and other .Net code and run
  43. them on platforms that originally are not .Net compatible like Linux.<br>
  44. <br>
  45. <span class="RakNetBlueHeader">Choices to Make.<br>
  46. <br>
  47. </span>You may choose to use the tools with RakNet or start
  48. from scratch.<br>
  49. <br>
  50. On Windows batch tools are provided make the
  51. process easier.
  52. These tools are located under the Swig Directory under
  53. DependentExtensions. For Linux&nbsp;the tools will
  54. use Wget to pull down Swig and install version 2.0.00 if Swig is not
  55. installed.<br>
  56. <br>
  57. You may also download Swig yourself and compile them by specifying the
  58. options manually. In the manual portion the options used&nbsp;will
  59. be explained.<br>
  60. <br>
  61. <span class="RakNetBlueHeader">Step Summary<br>
  62. <br>
  63. </span><span style="font-weight: bold;">Manually:<br>
  64. </span>
  65. <ol>
  66. <li>Download Swig,&nbsp;see&nbsp;"Downloading
  67. Swig"</li>
  68. <li>Generate the Swig files, see "Generating
  69. the Swig Files Manually"</li>
  70. <li>Create the DLL, see "Creating the Swig Wrapped DLL
  71. Project"</li>
  72. <li>Create the C# project. see &nbsp;"Creating the C#
  73. project"</li>
  74. </ol>
  75. <span style="font-weight: bold;">Using tools:<br>
  76. <br>
  77. *Windows<br>
  78. <br>
  79. -Using DLL_Swig\RakNet.sln solution<br>
  80. </span>
  81. <ol>
  82. <li>Download Swig, see section "Downloading
  83. Swig"</li>
  84. <li>If you do not plan on
  85. using&nbsp;SQLiteClientLoggerPlugin,
  86. DependentExtensions\Swig\DLL_Swig\RakNet.sln already contains a DLL
  87. project that makes the Swig files, builds the DLL, and copies it to the
  88. C# sample. Perform a rebuild on
  89. this.</li>
  90. <li>Create the C# project see &nbsp;"Creating the C#
  91. project"</li>
  92. </ol>
  93. <span style="font-weight: bold;">-Not using DLL_Swig
  94. project</span><span style="font-weight: bold;"><br>
  95. </span>
  96. <ol>
  97. <li>Download Swig,&nbsp;See section "Downloading
  98. Swig"</li>
  99. <li>Generate the Swig files, see "Generating
  100. the Swig Files Using Included&nbsp;Tools"</li>
  101. <li>Create the DLL, see "Creating the Swig Wrapped DLL
  102. Project" </li>
  103. <li>Create the C# project see &nbsp;"Creating the C#
  104. project"</li>
  105. </ol>
  106. <br>
  107. <span style="font-weight: bold;">*Linux<br>
  108. </span>
  109. <ol>
  110. <li>Download Swig,&nbsp;See section "Downloading
  111. Swig".</li>
  112. <li>Generate the Swig files, see "Generating
  113. the Swig Files Using Included tools"</li>
  114. <li>Create the C# project see &nbsp;"Creating the C#
  115. project"</li>
  116. </ol>
  117. <span class="RakNetBlueHeader"></span></td>
  118. </tr>
  119. </tbody>
  120. </table>
  121. <table border="0" width="100%">
  122. <tbody>
  123. <tr>
  124. <td class="RakNetWhiteHeader" bgcolor="#2c5d92"><img src="spacer.gif" height="1" width="8">Downloading
  125. Swig</td>
  126. </tr>
  127. </tbody>
  128. </table>
  129. <table border="0" cellpadding="10" cellspacing="0" width="100%">
  130. <tbody>
  131. <tr>
  132. <td> <span class="RakNetBlueHeader"><font size="+2">Windows</font><br>
  133. <br>
  134. Download
  135. Swig and Unzip.<br>
  136. <br>
  137. </span>
  138. <ol>
  139. <li>Go to <a href="http://www.swig.org/">http://www.swig.org/</a></li>
  140. <li>On the left hand side click <a href="http://www.swig.org/survey.html">Download</a>.</li>
  141. <li>Either fill out the survey or click the <a href="http://www.swig.org/download.html">Download area</a>
  142. link.</li>
  143. <li>It will say&nbsp;Windows users should download
  144. &lt;link&gt; click on the link.</li>
  145. <li>Unzip to C:\Swig or where you prefer C:\Swig will be
  146. used for this tutorial.</li>
  147. <li>If you wish to use the DLL_Swig project you will need
  148. to add to the path variable as shown below.</li>
  149. </ol>
  150. <span class="RakNetBlueHeader">
  151. Adding Swig to the Path Variable.<br>
  152. <br>
  153. </span>
  154. <ol>
  155. <li>Right click My Computer and click Properties.</li>
  156. <li>Click on the Advanced tab.</li>
  157. <li>Under Advanced, there is an Environment Variables
  158. button click it.</li>
  159. <li>Click the on the Path variable</li>
  160. <li>Click the Edit button</li>
  161. <li>Add the path C:\Swig or wherever you unzipped Swig to.<br>
  162. </li>
  163. </ol>
  164. <table>
  165. <tbody>
  166. <tr>
  167. <td><A href="PathVariableShot.jpg"><img src="PathVariableShot.jpg"></a></span><br>
  168. </td>
  169. </tr>
  170. <tr align="center">
  171. <td><span style="font-weight: bold;">The
  172. path variable screen</span></td>
  173. </tr>
  174. </tbody>
  175. </table>
  176. <span class="RakNetBlueHeader"><font size="+2">Linux</font></span><br>
  177. <br>
  178. <span class="RakNetBlueHeader">Download
  179. Swig,Unzip,Make, and Install.<br>
  180. <br>
  181. <span class="RakNetManualTextBody">Note: You may be
  182. able to
  183. install Swig using your favorite package manager, if you can go that
  184. route do so. The instructions vary depending on your package manager
  185. and distribution. The batch file will attempt to install 1.6, but it is
  186. recommended to use the package manager if you are able to.</span></span>
  187. <ol>
  188. <li>Go to <a href="http://www.swig.org/">http://www.swig.org/</a></li>
  189. <li>On the left hand side click <a href="http://www.swig.org/survey.html">Download</a>.</li>
  190. <li>Either fill out the survey or click the <a href="http://www.swig.org/download.html">Download area</a>
  191. link.</li>
  192. <li>It will say latest development release is
  193. &lt;link&gt; click on the link.</li>
  194. <li>Open a terminal</li>
  195. <li>Change to the directory you download swig into</li>
  196. <li>type tar xzf swig-VERSIONNUMBER.tar.gz and&nbsp;
  197. hit enter<br>
  198. </li>
  199. <li>type cd VERSIONNUMBER and&nbsp; hit enter</li>
  200. <li>type ./configure and&nbsp; hit enter </li>
  201. <li>type make and&nbsp; hit enter</li>
  202. <li>switch to your root user, or if user is a sudo user
  203. skip to next step</li>
  204. <li>if root type make install and hit enter, other wise
  205. type sudo make install and hit enter if user is a sudo user.<br>
  206. </li>
  207. </ol>
  208. </td>
  209. </tr>
  210. </tbody>
  211. </table>
  212. <table border="0" width="100%">
  213. <tbody>
  214. <tr>
  215. <td class="RakNetWhiteHeader" bgcolor="#2c5d92">&nbsp;Generating
  216. the Swig Files Using Included Tools</td>
  217. </tr>
  218. </tbody>
  219. </table>
  220. <table border="0" cellpadding="10" cellspacing="0" width="100%">
  221. <tbody>
  222. <tr>
  223. <td><span class="RakNetBlueHeader">Generating
  224. the Swig Files Using Included Tools on Windows.<br>
  225. <br>
  226. </span><font size="-1">Note:
  227. This step on Windows can be skipped if you are using the included
  228. DLL_Swig project as it runs the tools on rebuild.</font><br>
  229. <ol>
  230. <li>Click the start menu and click on run. In Vista click
  231. start-&gt;search&nbsp;type "run" hit enter.</li>
  232. <li>Type cmd and hit enter.</li>
  233. <li>In the next command PATH_TO_RAKNET_SWIG_FILES is the
  234. path to
  235. the swig directory. For example C:\RakNet\DependentExtensions\Swig</li>
  236. <li>Type cd&nbsp;PATH_TO_RAKNET_SWIG_FILES hit enter</li>
  237. <li>In the next command PATH_TO_RAKNETSOURCE is the path
  238. to the swig source directory. For example: C:\RakNet\Source.
  239. PATH_TO_SWIG is an unquoted path with a trailing slash to
  240. the&nbsp;Swig directory Example: C:\Swig\. If you added swig to
  241. your path variable then&nbsp;PATH_TO_SWIG is not needed and can be
  242. ignored.</li>
  243. <li>Enter MakeSwig.bat
  244. PATH_TO_RAKNETSOURCE&nbsp;PATH_TO_SWIG. For example, MakeSwig.bat c:\RakNet\Source c:\swigwin-2.0.9 <br>
  245. </li>
  246. <a href='javascript:toggleDisplay("ExtraInstructions1");'>Click
  247. to toggle extra instructions for SQLiteClientLoggerPlugin</a>
  248. <div id="ExtraInstructions1" name="ExtraInstructions1" style="display: none;"><li>If you want to use
  249. SQLiteClientLoggerPlugin skip #6, the next steps will be used instead.</li>
  250. <li>If you have added swig to your path variable, just
  251. use "" for PATH_TO_SWIG</li>
  252. <li>PATH_TO_SQLITEPLUGIN is the path to the SQLite plugin
  253. directory. EX: C:\RakNet\DependentExtensions\SQLite3Plugin</li>
  254. <li>Type MakeSwig.bat
  255. PATH_TO_RAKNETSOURCE&nbsp;PATH_TO_SWIG
  256. &nbsp;PATH_TO_SQLITEPLUGIN hit enter</li>
  257. </div>
  258. <li>Goto "Creating the Swig Wrapped DLL Project"</li>
  259. </ol>
  260. <span class="RakNetBlueHeader">Generating
  261. the Swig Files Using Included Tools on Linux.<br>
  262. <br>
  263. <span class="RakNetManualTextBody">Note: The Linux
  264. batch <span class="RakNetBlueHeader"></span><span class="RakNetBlueHeader"></span>requires Wget,Tar,Make
  265. and GCC&nbsp; to be installed, unless swig is already installed.
  266. Most of the time </span></span><span class="RakNetBlueHeader"><span class="RakNetManualTextBody">Wget,Tar,Make and GCC are</span></span><span class="RakNetBlueHeader"><span class="RakNetManualTextBody"> already installed.</span><br>
  267. </span>
  268. <ol>
  269. <li>Open a terminal if you are not already at one.<br>
  270. </li>
  271. <li>In the next command PATH_TO_RAKNET_SWIG_FILES is the
  272. path to
  273. the swig directory. For example
  274. /home/usr/RakNet/DependentExtensions/Swig</li>
  275. <li>Type cd&nbsp;PATH_TO_RAKNET_SWIG_FILES hit enter</li>
  276. <li>Type chmod u+x MakeSwig.sh<br>
  277. </li>
  278. <li>In the next command PATH_TO_RAKNETSOURCE is the path
  279. to the swig source directory. For
  280. example:&nbsp;/home/usr/RakNet/Source</li>
  281. <li>Type ./MakeSwig.sh PATH_TO_RAKNETSOURCE hit enter</li>
  282. <a href='javascript:toggleDisplay("ExtraInstructions2");'>Click
  283. to toggle extra instructions for SQLiteClientLoggerPlugin</a>
  284. <div id="ExtraInstructions2" name="ExtraInstructions2" style="display: none;"><li>If you want to use
  285. SQLiteClientLoggerPlugin skip #6, the next steps will be used instead.<br>
  286. </li>
  287. <li>PATH_TO_SQLITEPLUGIN is the path to the SQLite plugin
  288. directory.
  289. EX:&nbsp;/home/usr/RakNet/DependentExtensions/SQLite3Plugin<br>
  290. </li>
  291. <li>Type MakeSwig.sh
  292. PATH_TO_RAKNETSOURCE&nbsp;PATH_TO_SQLITEPLUGIN hit enter<br>
  293. </li>
  294. </div>
  295. <li>Skip to "Creating the C# project".&nbsp;
  296. &nbsp;</li>
  297. </ol>
  298. </td>
  299. </tr>
  300. </tbody>
  301. </table>
  302. <table border="0" width="100%">
  303. <tbody>
  304. <tr>
  305. <td class="RakNetWhiteHeader" bgcolor="#2c5d92">&nbsp;Generating
  306. the Swig Files Manually</td>
  307. </tr>
  308. </tbody>
  309. </table>
  310. <table border="0" cellpadding="10" cellspacing="0" width="100%">
  311. <tbody>
  312. <tr>
  313. <td><span class="RakNetBlueHeader"><font size="+2">Windows</font><br>
  314. </span><span class="RakNetBlueHeader"><br>
  315. </span>
  316. <span class="RakNetBlueHeader">Generate the Swig
  317. Files</span><br>
  318. <ol>
  319. <li>Click the start menu and click on run. In Vista click
  320. start-&gt;search&nbsp;type "run" hit enter.</li>
  321. <li>Type cmd and hit enter.</li>
  322. <li>In the next command PATH_TO_RAKNET_SWIG_FILES is the
  323. path to
  324. the swig directory. For example C:\RakNet\DependentExtensions\Swig</li>
  325. <li>Type cd&nbsp;PATH_TO_RAKNET_SWIG_FILES hit enter</li>
  326. <li>In the next command PATH_TO_RAKNETSOURCE is the path
  327. to the swig source directory. For example: C:\RakNet\Source</li>
  328. <li>Type C:\Swig\swig -c++ -csharp -namespace RakNet -I"PATH_TO_RAKNETSOURCE"
  329. -I"SwigInterfaceFiles" -outdir SwigOutput\SwigCSharpOutput -o
  330. SwigOutput\CplusDLLIncludes\RakNet_wrap.cxx SwigInterfaceFiles\RakNet.i
  331. hit enter</li>
  332. <a href='javascript:toggleDisplay("ExtraInstructions3");'>Click
  333. to toggle extra instructions for SQLiteClientLoggerPlugin</a>
  334. <div id="ExtraInstructions3" name="ExtraInstructions3" style="display: none;"><li>If you want to use
  335. SQLiteClientLoggerPlugin skip #6</li>
  336. <li>PATH_TO_SQLITEPLUGIN is the path to the SQLite plugin
  337. directory. EX: C:\RakNet\DependentExtensions\SQLite3Plugin</li>
  338. <li>Type C:\Swig\swig -c++ -csharp -namespace RakNet -I"PATH_TO_RAKNETSOURCE" -I"SwigInterfaceFiles" -I"PATH_TO_SQLITEPLUGIN"
  339. -DSWIG_ADDITIONAL_SQL_LITE -outdir SwigOutput\SwigCSharpOutput -o
  340. SwigOutput\CplusDLLIncludes\RakNet_wrap.cxx SwigInterfaceFiles\RakNet.i
  341. hit enter&nbsp;</li>
  342. </div>
  343. </ol>
  344. <span class="RakNetBlueHeader"><font size="+2">Linux</font></span><br>
  345. <span class="RakNetBlueHeader"><br>
  346. </span> <span class="RakNetBlueHeader">Generate
  347. the Swig
  348. Files</span><br>
  349. <ol>
  350. <li>Open a terminal<br>
  351. </li>
  352. <li>In the next command PATH_TO_RAKNET_SWIG_FILES is the
  353. path to
  354. the swig directory. For example
  355. /home/usr/RakNet/DependentExtensions/Swig</li>
  356. <li>Type cd&nbsp;PATH_TO_RAKNET_SWIG_FILES hit enter</li>
  357. <li>In the next command PATH_TO_RAKNETSOURCE is the path
  358. to the swig source directory. For example: /home/usr/RakNet/Source</li>
  359. <li>Type swig -c++ -csharp -namespace RakNet
  360. -I"PATH_TO_RAKNETSOURCE"
  361. -I"SwigInterfaceFiles" -outdir SwigOutput/SwigCSharpOutput -o
  362. SwigOutput/CplusDLLIncludes/RakNet_wrap.cxx SwigInterfaceFiles/RakNet.i
  363. and hit enter</li>
  364. <a href='javascript:toggleDisplay("ExtraInstructions4");'>Click
  365. to toggle extra instructions for SQLiteClientLoggerPlugin</a>
  366. <div id="ExtraInstructions4" name="ExtraInstructions4" style="display: none;"><li>f you want to use
  367. SQLiteClientLoggerPlugin skip #6</li>
  368. <li>PATH_TO_SQLITEPLUGIN is the path to the SQLite plugin
  369. directory.
  370. EX:&nbsp;/home/usr/RakNet/DependentExtensions/SQLite3Plugin</li>
  371. <li>Type swig -c++ -csharp -namespace RakNet
  372. -I"PATH_TO_RAKNETSOURCE"
  373. -I"SwigInterfaceFiles" -I"PATH_TO_SQLITEPLUGIN"
  374. -DSWIG_ADDITIONAL_SQL_LITE -outdir SwigOutput/SwigCSharpOutput -o
  375. SwigOutput/CplusDLLIncludes/RakNet_wrap.cxx SwigInterfaceFiles/RakNet.i
  376. and hit enter</li>
  377. </div>
  378. </ol>
  379. <span class="RakNetBlueHeader">Swig Options Explained<br>
  380. <br>
  381. </span><span style="font-weight: bold;">-c++ </span><br>
  382. <br>
  383. This must come first. This means that the source files are C++ not C.<br>
  384. <br>
  385. <span style="font-weight: bold;">-csharp&nbsp;</span><br>
  386. <span style="font-weight: bold;"><br>
  387. </span>This is the target language. Currently the files are
  388. made for C# and may not work with the other options.<br>
  389. <br>
  390. <span style="font-weight: bold;">-namespace RakNet</span><br>
  391. <span style="font-weight: bold;"><br>
  392. </span>This puts the generated files in the C# namespace RakNet<br>
  393. <span style="font-weight: bold;"><br>
  394. -I"PATH_TO_RAKNETSOURCE"
  395. </span><br>
  396. <br>
  397. This option includes the directory for any source and includes if
  398. different from the interface file location.<br>
  399. <br>
  400. <span style="font-weight: bold;">-I"SwigInterfaceFiles"
  401. </span><br>
  402. <br>
  403. This option includes the directory for the interface files.<br>
  404. <br>
  405. <span style="font-weight: bold;">-outdir
  406. SwigOutput/SwigCSharpOutput </span><br>
  407. <br>
  408. This is where the output files to be included in the target language
  409. are placed.<br>
  410. <br>
  411. <span style="font-weight: bold;">-o
  412. SwigOutput/CplusDLLIncludes/RakNet_wrap.cxx</span><br>
  413. <span class="RakNetBlueHeader"><br>
  414. </span>This is where the file that is included in the DLL
  415. project is placed.<br>
  416. <br>
  417. <span style="font-weight: bold;">*The below two are
  418. used if SQLiteClientLoggerPlugin is used:</span><br>
  419. <br>
  420. <span style="font-weight: bold;">-I"PATH_TO_SQLITEPLUGIN"
  421. <br>
  422. <br>
  423. </span>Another include directory, the base directory where
  424. the SQLite plugin is.<br>
  425. <br>
  426. <span style="font-weight: bold;">-DSWIG_ADDITIONAL_SQL_LITE<br>
  427. <br>
  428. </span>A conditional compilation symbol, defined to include
  429. SQLiteClientLoggerPlugin.<span style="font-weight: bold;"><br>
  430. </span><span class="RakNetBlueHeader"><br>
  431. </span></td>
  432. </tr>
  433. </tbody>
  434. </table>
  435. <table border="0" width="100%">
  436. <tbody>
  437. <tr>
  438. <td class="RakNetWhiteHeader" bgcolor="#2c5d92"><img src="spacer.gif" height="1" width="8">Creating
  439. the Swig Wrapped DLL Project</td>
  440. </tr>
  441. </tbody>
  442. </table>
  443. <table border="0" cellpadding="10" cellspacing="0" width="100%">
  444. <tbody>
  445. <tr>
  446. <td>
  447. <p class="RakNetBlueHeader"><span class="RakNetBlueHeader"><font size="+2">Windows</font></span></p>
  448. <span style="font-weight: bold;"><br>
  449. </span>Note: If you do not plan on
  450. using&nbsp;SQLiteClientLoggerPlugin,
  451. DependentExtensions\Swig\DLL_Swig\RakNet.sln already contains a DLL
  452. project that makes the Swig files, builds the DLL, and copies it to the
  453. C# sample. You do not need to run these steps if you use that project.
  454. In that case, run the solution, rebuild the project, and goto "Creating
  455. the C# project"<span style="font-weight: bold;"><br>
  456. </span>
  457. <p class="RakNetBlueHeader">Creating the
  458. Swig&nbsp; DLL</p>
  459. <ol>
  460. <li>Create a DLL project. I'll assume you know how to do
  461. this. In MSVC 7 you would create an empty project, then under
  462. Application Settings you check DLL and empty project.</li>
  463. <li>Add the source files under the /Source directory to
  464. the project.</li>
  465. <li>Add <span style="font-size: 12pt;">RakNet.cxx
  466. from&nbsp;Swigtools/CplusDLLIncludes</span></li>
  467. <a href='javascript:toggleDisplay("ExtraInstructions5");'>Click
  468. to toggle extra instructions for SQLiteClientLoggerPlugin</a>
  469. <div id="ExtraInstructions5" name="ExtraInstructions5" style="display: none;"><li>Add to the project these
  470. files under DependentExtensions: SQLite3Plugin\SQLite3ClientPlugin.h,
  471. SQLite3Plugin\SQLite3PLuginCommon.h,
  472. SQLite3Plugin\Logger\ClientOnly\SQLiteClientLoggerPlugin.h,
  473. SQLite3Plugin\Logger\SQLliteLoggerCommon.h,
  474. SQLite3Plugin\SQLite3ClientPlugin.cpp,
  475. SQLite3Plugin\SQLite3PLuginCommon.cpp,
  476. SQLite3Plugin\Logger\ClientOnly\SQLiteClientLoggerPlugin.cpp,
  477. SQLite3Plugin\Logger\SQLliteLoggerCommon.cpp</li>
  478. <li>Add to "Additional Include Directories" the path to
  479. these folders in the DependentExtensions directory:
  480. SQLite3Plugin\Logger\ClientOnly, SQLite3Plugin\Logger, SQLite3Plugin</li>
  481. </div>
  482. <li>Add to "Additional Include Directories" your
  483. directory with the source files.</li>
  484. <li>Import
  485. ws2_32.lib, or wsock32.lib if you don't have Winsock 2 installed. In
  486. MSVC 7 you can right click on the project, select configuration
  487. properties / linker / input / additional dependencies and type
  488. "ws2_32.lib" in there.</font></li>
  489. <li>Set
  490. your project to use multi-threaded runtime libraries. In MSVC 7 you can
  491. right click on the project, select configuration properties / C/C++ /
  492. Code Generation / Runtime Library and change it to Multi-threaded (/MT).</font></li>
  493. <li>Add
  494. _RAKNET_DLL to the Preprocessor Definitions. In VS Project Properties
  495. -&gt; Configuration Properties -&gt; C/C++ -&gt;
  496. PreProcessor -&gt; Preprocessor Definitions</font></li>
  497. <li>Set
  498. the character set to "not set".In VS Project Properties -&gt;
  499. Configuration Properties -&gt; General-&gt; Character Set </font></li>
  500. <li>Optionally
  501. set your <a href="preprocessordirectives.html">preprocessor
  502. directives.</a></font></li>
  503. <li>Then
  504. hit F7 or the equivalent to build your DLL and Lib.</font></li>
  505. </ol>
  506. <table>
  507. <tbody>
  508. <tr>
  509. <td><a href="makedll.jpg"><img src="makedllsmall.jpg"></a><br>
  510. </td>
  511. </tr>
  512. <tr align="center">
  513. <td><b>Creating an empty DLL project in .net
  514. 2003</b></td>
  515. </tr>
  516. </tbody>
  517. </table>
  518. <table>
  519. <tbody>
  520. <tr>
  521. <td><a href="multithreadeddebug.jpg"><img src="multithreadeddebugsmall.jpg"></a><br>
  522. </td>
  523. </tr>
  524. <tr align="center">
  525. <td><b>Setting Multithreaded debug in .net 2003</b></td>
  526. </tr>
  527. </tbody>
  528. </table>
  529. <table>
  530. <tbody>
  531. <tr>
  532. <td><a href="ws2_32include.jpg"><img src="ws2_32includesmall.jpg"></a><br>
  533. </td>
  534. </tr>
  535. <tr align="center">
  536. <td><b>Including ws2_32.lib in .net 2003</b>
  537. </td>
  538. </tr>
  539. </tbody>
  540. </table>
  541. <br>
  542. <p class="RakNetBlueHeader"><span class="RakNetBlueHeader"><font size="+2">Linux</font></span></p>
  543. <p class="RakNetBlueHeader">Creating the
  544. Swig&nbsp; Dynamic Link</p>
  545. <p class="RakNetBlueHeader"><span class="RakNetManualTextBody">Note:
  546. If you ran the linux batch tool it will have made the dynamic link and
  547. attempted to install it, so you may skip these steps if it ran
  548. successfully.</span><br>
  549. </p>
  550. <ol>
  551. <li>In the next command PATH_TO_RAKNET_SWIG_FILES is the
  552. path to
  553. the swig directory.&nbsp;<span style="font-size: 12pt; font-family: &quot;Times New Roman&quot;;">
  554. EX:: </span>../DependentExtensions/Swig<span style="font-size: 12pt; font-family: &quot;Times New Roman&quot;;"></span></li>
  555. <li>g++
  556. *.cpp&nbsp;PATH_TO_RAKNET_SWIG_FILES/SwigOutput/CplusDLLIncludes/RakNet_wrap.cxx
  557. -l pthread -I./ -shared -o RakNet</li>
  558. <li>Note: In the previous command -l pthread is lower
  559. case L while -I./ is uppercase i.</li>
  560. <a href='javascript:toggleDisplay("ExtraInstructions6");'>Click
  561. to toggle extra instructions for SQLiteClientLoggerPlugin</a>
  562. <div id="ExtraInstructions6" name="ExtraInstructions6" style="display: none;"><li>If you wish to use
  563. SQLiteClientLoggerPlugin in the place of #2 use the below instructions</li>
  564. <li>&nbsp;PATH_TO_SQLITEPLUGIN is the path to the
  565. SQLite plugin directory. EX:
  566. /home/usr/RakNet/DependentExtensions/SQLite3Plugin</li>
  567. <li>g++
  568. *.cpp&nbsp;PATH_TO_RAKNET_SWIG_FILES/SwigOutput/CplusDLLIncludes/RakNet_wrap.cxx
  569. PATH_TO_SQLITEPLUGIN\SQLite3ClientPlugin.cpp&nbsp;
  570. PATH_TO_SQLITEPLUGIN \SQLite3PLuginCommon.cpp&nbsp;
  571. PATH_TO_SQLITEPLUGIN
  572. \Logger\ClientOnly\SQLiteClientLoggerPlugin.cpp&nbsp;
  573. PATH_TO_SQLITEPLUGIN \Logger\SQLliteLoggerCommon.cpp&nbsp; -l
  574. pthread
  575. -I./&nbsp;-IPATH_TO_SQLITEPLUGIN\Logger\ClientOnly&nbsp;-IPATH_TO_SQLITEPLUGIN\Logger&nbsp;-IPATH_TO_SQLITEPLUGIN
  576. -shared -o RakNet</li>
  577. </div>
  578. <li>A file called RakNet should be created that will be
  579. copied in the next section<br>
  580. </li>
  581. </ol>
  582. <br>
  583. </td>
  584. </tr>
  585. </tbody>
  586. </table>
  587. <table border="0" width="100%">
  588. <tbody>
  589. <tr>
  590. <td class="RakNetWhiteHeader" bgcolor="#2c5d92"><img src="spacer.gif" height="1" width="8">Creating
  591. the C# project</td>
  592. </tr>
  593. </tbody>
  594. </table>
  595. <table border="0" cellpadding="10" cellspacing="0" width="100%">
  596. <tbody>
  597. <tr>
  598. <td><span class="RakNetBlueHeader"><font size="+2">Windows<br>
  599. <br>
  600. </font></span><span class="RakNetBlueHeader">C#
  601. Project
  602. Setup<br>
  603. </span>
  604. <ol>
  605. <li>Create a new C# project. In the included sample a
  606. console project is used.</li>
  607. <li>If you wish to keep the project cleaner create a new
  608. folder called Swig. Right click the project and go to Add -&gt; New
  609. folder</li>
  610. <li>Add the source files that were generated under
  611. the&nbsp;SwigOutput\SwigCSharpOutput directory to
  612. the project.The first step to doing this is right clicking the project,
  613. or if you added a folder right click the folder.</li>
  614. <li>Go to Add -&gt; Existing Item.&nbsp;</li>
  615. <li>Browse to the&nbsp;SwigOutput\SwigCSharpOutput
  616. directory.</li>
  617. <li>&nbsp;If
  618. you want to link to the files rather than create a copy click on the
  619. arrow next to add and add a link. Otherwise click add.</li>
  620. <li>Copy the DLL created in the previous step to the same
  621. folder as the binary. Example: bin\Debug</li>
  622. <li>If you wish the project to be compatible with 64 bit
  623. vista you need to use the following steps.</li>
  624. <li>When the project is opnen there should be a menu item
  625. called Build. Click it.</li>
  626. <li>Go to Configuration manager and click it.</li>
  627. <li>On the top right there is a drop down menu called
  628. Active Solution platform.</li>
  629. <li>If X86 is in the project menu click it and go to step
  630. 16.</li>
  631. <li>If not click New.</li>
  632. <li>Under "Type or select the new platform" pick x86.
  633. Copy settings should be set to "Any CPU"</li>
  634. <li>Make sure "Create new project platforms" is checked
  635. and click ok.</li>
  636. <li>Click on "Active Solutions configuration" in the top
  637. left.</li>
  638. <li>Pick the next item after the one currently selected
  639. if that item is not &lt;New&gt; or &lt;Edit&gt;.</li>
  640. <li>Repeat 11-17 for that item.</li>
  641. <li>There should be a list under "Project Contexts".</li>
  642. <li>Under the "Platform" column it should say x86 under
  643. each item, if not change it to x86.</li>
  644. <li>Thre
  645. should be an column called "Configuration", cycle through all the items
  646. except for &lt;New&gt; and &lt;Edit&gt; and make sure
  647. that #20 is true.</li>
  648. <li>Do #20-21 for each item in the list.</li>
  649. <li><b>Make sure you have "using RakNet;" at the top of the files using RakNet. If this tutorial was followed the generated files are in the RakNet namespace.</b></li>
  650. </ol>
  651. <table>
  652. <tbody>
  653. <tr>
  654. <td><A href="CSharpBuildConfiguration.jpg"><img src="CSharpBuildConfiguration.jpg"></a><br>
  655. </td>
  656. </tr>
  657. <tr align="center">
  658. <td><span style="font-weight: bold;">Example of steps 9-21 to run on 64-bit systems. </span></td>
  659. </tr>
  660. </tbody>
  661. </table>
  662. <span class="RakNetBlueHeader"><br>C# Sample</span><br>
  663. <span class="RakNetBlueHeader"></span>&nbsp;<br>
  664. A C# sample project is included under
  665. DependentExtensions\Swig\SwigWindowsCSharpSample. The DLL file is not
  666. included and needs to be copied to the bin/Debug or the bin/Release
  667. folder depending on whether or not you are doing a release or debug
  668. build. If the DLL_Swig project is used the dll is copied automatically.<br>
  669. <br>
  670. <span class="RakNetBlueHeader"><font size="+2">Linux<br>
  671. <br>
  672. </font></span><span class="RakNetBlueHeader">Installing
  673. Mono, if it is not Installed</span><br>
  674. <span class="RakNetBlueHeader"><font size="+2"><br>
  675. </font></span><span class="RakNetBlueHeader"><span class="RakNetManualTextBody">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.
  676. You may be able to install Mono using your favorite package manager, if
  677. you can go that route do so. The instructions vary depending on your
  678. package manager and distribution. Some package manager have different
  679. options for the C# compiler. This tutorial assumes <span style="font-weight: bold;">gmcs</span> is installed.</span></span><br>
  680. <br>
  681. <ol>
  682. <li>Go to <a href="http://www.go-mono.com/mono-downloads/download.html">http://www.go-mono.com/mono-downloads/download.html</a></li>
  683. <li>Download the linux version</li>
  684. <li>open a terminal</li>
  685. <li>change to the directory you downloaded mono to..</li>
  686. <li>type tar xzvf mono-VERSION.tar.gz hit enter</li>
  687. <li>type cd mono-VERSION hit enter</li>
  688. <li>type ./configure --prefix=/usr/local and&nbsp;
  689. hit enter </li>
  690. <li>type make and&nbsp; hit enter</li>
  691. <li>switch to your root user, or if user is a sudo user
  692. skip to next step</li>
  693. <li>if root type make install and hit enter, other wise
  694. type sudo make install and hit enter if user is a sudo user.</li>
  695. </ol>
  696. <br>
  697. <span class="RakNetBlueHeader">C# Project
  698. Setup<br>
  699. <br>
  700. </span><span class="RakNetBlueHeader"><span class="RakNetManualTextBody">Note: If you used the included
  701. tools and just want to run the sample you may skip this section.</span></span><br>
  702. <ol>
  703. <li>Copy the dynamic link library to /usr/lib and rename
  704. it to RakNet with no extension if it is not already.<br>
  705. </li>
  706. <li>Copy the files in Swigtools/SwigCSharpOutput into
  707. your project directory.</li>
  708. <li>Create your main C# .cs file in that folder.</li>
  709. <li><b>Make sure you have "using RakNet;" at the top of the files using RakNet. If this tutorial was followed the generated files are in the RakNet namespace.</b></li>
  710. </ol>
  711. <span class="RakNetBlueHeader">Building the Project</span>
  712. <ol>
  713. <li>Type gmcs *.cs -out:ExecutableName.exe where
  714. ExecutableName is the name
  715. you want and hit enter.</li>
  716. <li>The file can be ran with mono ExecutableName.exe<br>
  717. <br>
  718. </li>
  719. </ol>
  720. <span class="RakNetBlueHeader">C# Sample</span><br>
  721. <span class="RakNetBlueHeader"></span>&nbsp;<br>
  722. A C# sample&nbsp;is included under
  723. DependentExtensions/Swig/SwigLinuxCSharpSample. The DLL
  724. file is not included and needs to be copied to /usr/lib as per the
  725. earlier instructions. If the tools are used the cs files are
  726. automatically copied to the sample directory and there is an attempt by
  727. tools to copy the dll to /usr/lib.
  728. <ol>
  729. </ol>
  730. </td>
  731. </tr>
  732. </tbody>
  733. </table>
  734. <table border="0" width="100%">
  735. <tbody>
  736. <tr>
  737. <td class="RakNetWhiteHeader" bgcolor="#2c5d92"><img src="spacer.gif" height="1" width="8">Limitations</td>
  738. </tr>
  739. </tbody>
  740. </table>
  741. <table border="0" cellpadding="10" cellspacing="0" width="100%">
  742. <tbody>
  743. <tr>
  744. <td><span class="RakNetBlueHeader">Limitations<br>
  745. </span>
  746. <ol>
  747. <li>BitStream may have problems if larger than 9
  748. megabytes.</li>
  749. </ol>
  750. <br>
  751. <ol>
  752. </ol>
  753. </td>
  754. </tr>
  755. </tbody>
  756. </table>
  757. <table border="0" width="100%">
  758. <tbody>
  759. <tr>
  760. <td class="RakNetWhiteHeader" bgcolor="#2c5d92">Important
  761. Information<br>
  762. </td>
  763. </tr>
  764. </tbody>
  765. </table>
  766. <table border="0" cellpadding="10" cellspacing="0" width="100%">
  767. <tbody>
  768. <tr>
  769. <td><span class="RakNetBlueHeader">Important Information<br>
  770. </span>
  771. <ol>
  772. <li>RakPeer,RakString,FullyConnectedMesh2,UDPForwarder, and
  773. UDPProxyCoordinator need to be released before the program ends.Any item that go out of scope before program end just needs to be garbage collected, so items not in main or global generally do not have issues. For these just call the GC before program end.For globals and items in main the items can be released with
  774. the Dispose method if new was used, or DestroyInstance if
  775. CreateInstance was used.<br>
  776. </li>
  777. </ol>
  778. <br>
  779. <ol>
  780. </ol>
  781. </td>
  782. </tr>
  783. </tbody>
  784. </table>
  785. <br>
  786. <table border="0" width="100%">
  787. <tbody>
  788. <tr>
  789. <td class="RakNetWhiteHeader" bgcolor="#2c5d92"><img src="spacer.gif" height="1" width="8">See Also</td>
  790. </tr>
  791. </tbody>
  792. </table>
  793. <table border="0" cellpadding="10" cellspacing="0" width="100%">
  794. <tbody>
  795. <tr>
  796. <td>
  797. <p><a href="index.html">Index</a><br>
  798. </p>
  799. </td>
  800. </tr>
  801. </tbody>
  802. </table>
  803. <script type="text/javascript">
  804. function toggleDisplay(divId) {
  805. var div = document.getElementById(divId);
  806. div.style.display = (div.style.display=="block" ? "none" : "block");
  807. }
  808. </script>
  809. </body></html>
粤ICP备19079148号