Jump to content

Compiling SDK CodeBlocks Linux: Difference between revisions

From Kingpin Wiki
Created page with "<p>You should know a little bit about linux before you can do this.<br />Kingpin in the past only compiled under gcc 2.7.2.3 compiler.<br />You mostly only get gcc 2.7.2.3 compiler under <a href="https://en.wikipedia.org/wiki/Red_Hat_Linux" target="_blank">Redhat 5.2</a><br />Maybe that was the Linux version that Xatrix used.<br />But I'm going to use a debian linux system <a href="https://xubuntu.org/" target="_blank">Xunbuntu</a> (Based on <a href="https://ubuntu...."
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
<p>You should know a little bit about linux before you can do this.<br />Kingpin in the past only compiled under gcc 2.7.2.3 compiler.<br />You mostly only get gcc 2.7.2.3 compiler under <a href="https://en.wikipedia.org/wiki/Red_Hat_Linux" target="_blank">Redhat 5.2</a><br />Maybe that was the Linux version that Xatrix used.<br />But I'm going to use a debian linux system <a href="https://xubuntu.org/" target="_blank">Xunbuntu</a> (Based on&nbsp;<a href="https://ubuntu.com/" target="_blank">Ubuntu</a> but loads faster and easyr in a <a href="https://en.wikipedia.org/wiki/VirtualBox" target="_blank">VirtualBox</a>)</p>
<h3>Introduction</h3>
<p>[https://en.wikipedia.org/wiki/Code::Blocks Code::Blocks] is a open-source IDE [https://en.wikipedia.org/wiki/Comparison_of_integrated_development_environments#C.2FC.2B.2B compared] to Microsoft [https://en.wikipedia.org/wiki/Microsoft_Visual_Studio Visual Studio]/[https://en.wikipedia.org/wiki/Microsoft_Visual_Studio_Express Express] <br />The good thing about [https://en.wikipedia.org/wiki/Open-source_software open-source] is that you can use it also in any OS.</p>
<p>Before you can do this you need to have done [[Compiling SDK Linux|Compiling with Linux]] otherwise you files probably are not ready yet for linux.</p>
<hr style="height: 2px; border-width: 0; background-color: #e7c258;" />
<hr style="height: 2px; border-width: 0; background-color: #e7c258;" />
<p>If you're using&nbsp;<a href="https://en.wikipedia.org/wiki/Red_Hat_Linux" target="_blank">Redhat 5.2</a> for some reasson (not really recommend) the orginale command line to compile gamei386.so was:<br /><strong>gcc *.c *.o -s -m486 -O6 -ffast-math -funroll-loops -fomit-frame-pointer -fexpensive-optimizations -malign-loops=2 -malign-jumps=2 -malign-functions=2 -fPIC -shared -o gamei386.so</strong><br />Or download the old <a href="https://www.kingpin.info/download/index.php?dir=kingpin/server/unofficial/sdk/linux/old/&amp;file=buildlinux_v0.zip" target="_blank">buildlinux.</a><br />The command line came from Xatrix <a href="https://www.kingpin.info/download/index.php?dir=kingpin/server/official/sdk/&amp;file=kingpinSDK-v121-navlib-linux-glibc-i386.zip" class="autoindex_a">kingpinSDK-v121-navlib-linux-glibc-i386.zip </a>in makefile.<br />Quite interesting to look at to know how they compiled the linux version.<br />But a few things have changes in the mean time also for the compiler.</p>
<h3>Creating a New Project</h3>
<hr style="height: 2px; border-width: 0; background-color: #e7c258;" />
<p>First, we must create the project in which we are going to work:</p>
<p>First of all you need gcc. Open a terminal:<br /><strong>sudo apt-get install gcc</strong><br />Now you all you need the libraries type next: <br /><strong>sudo apt-get install build-essential</strong> <br />This install the libraries<br />If you under a 64bit system you need also libc6-dev-i386:<br /><strong>sudo apt-get install&nbsp;libc6-dev-i386</strong></p>
<ol>
<p>Width <a href="https://www.kingpin.info/download/index.php?dir=kingpin/server/official/sdk/&amp;file=kpsdk.zip" target="_blank">kpsdk.zip</a> there some problems you need to fix.<br />Unzip the gamesrc to some folder.<br />Make everything lowercase in the folder with <a href="https://www.kingpin.info/download/index.php?dir=kingpin/utilities/linux/&amp;file=ccase.zip" target="_blank">ccase</a>:<br /><strong>chmod +x ccase</strong><br /><strong>./ccase -r *</strong></p>
<li>Start Code::Blocks</li>
<p>Search for every file that contains stricmp and not Q_stricmp and replace stricmp with Q_stricmp.<br />For example:<br /><code><span style="color: #ffff99;">&amp;&amp;&nbsp;&nbsp;&nbsp;&nbsp;(stricmp(self-&gt;enemy-&gt;client-&gt;pers.weapon-&gt;classname, "weapon_flamethrower") == 0))</span><br /></code>Becomes:<br /><code><span style="color: #ffff99;">&amp;&amp;&nbsp;&nbsp;&nbsp;&nbsp;(Q_stricmp(self-&gt;enemy-&gt;client-&gt;pers.weapon-&gt;classname, "weapon_flamethrower") == 0))</span></code></p>
<li>Close any open Workspaces</li>
<p>Open g_items.c and search for:<br /><code><span style="color: #ffff99;">static int&nbsp;&nbsp; &nbsp;jacket_armor_index;</span><br /><span style="color: #ffff99;">static int&nbsp;&nbsp; &nbsp;combat_armor_index;</span><br /><span style="color: #ffff99;">static int&nbsp;&nbsp; &nbsp;body_armor_index;</span><br /><span style="color: #ffff99;">static int&nbsp;&nbsp; &nbsp;power_screen_index;</span><br /><span style="color: #ffff99;">static int&nbsp;&nbsp; &nbsp;power_shield_index;</span><br /></code>and remove the static. So it says: int ????_armor_index; ???? with the correct name.</p>
<li>Choose from the menu File-&gt;New-&gt;Project..</li>
<p>Last bit to fix gcc version gcc 2.7.2.3 open game.h and search for:<br /><code><span style="color: #ffff99;">trace_t&nbsp;&nbsp; &nbsp;(*trace) (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passent, int contentmask);</span></code><br />replace it with:<br /><code><span style="color: #ffff99;">#if __linux__</span><br /><span style="color: #ffff99;">&nbsp;&nbsp; &nbsp;// callee_pop_aggregate_return attribute allows modern GCC to be used</span><br /><span style="color: #ffff99;">&nbsp;&nbsp; &nbsp;trace_t&nbsp;&nbsp; &nbsp;(*trace) (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passent, int contentmask) __attribute__((callee_pop_aggregate_return(0)));</span><br /><span style="color: #ffff99;">#else</span><br /><span style="color: #ffff99;">&nbsp;&nbsp; &nbsp;trace_t&nbsp;&nbsp; &nbsp;(*trace) (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passent, int contentmask);</span><br /><span style="color: #ffff99;">#endif</span></code></p>
<li>From the New From template dialog choose Projects-&gt;Shared Library and click Go.</li>
<p>Next open p_client.c and search for:<br /><code><span style="color: #ffff99;">trace_t&nbsp;&nbsp; &nbsp;PM_trace (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)</span></code><br />replace it with:<br /><code><span style="color: #ffff99;">#if __linux__</span><br /><span style="color: #ffff99;">trace_t&nbsp;&nbsp; &nbsp;__attribute__((callee_pop_aggregate_return(0))) PM_trace (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)</span><br /><span style="color: #ffff99;">#else</span><br /><span style="color: #ffff99;">trace_t&nbsp;&nbsp; &nbsp;PM_trace (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)</span><br /><span style="color: #ffff99;">#endif</span></code></p>
<li>A Shared Library dialog will start, click on Next.</li>
<p>&nbsp;Last one open q_shared.h and search for:<br /><code><span style="color: #ffff99;">trace_t&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;(*trace) (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end);</span></code><br />replace it with:<br /><code><span style="color: #ffff99;">#if __linux__</span><br /><span style="color: #ffff99;">&nbsp;&nbsp; &nbsp;// callee_pop_aggregate_return attribute allows modern GCC to be used</span><br /><span style="color: #ffff99;">&nbsp;&nbsp; &nbsp;trace_t&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;(*trace) (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end) __attribute__((callee_pop_aggregate_return(0)));</span><br /><span style="color: #ffff99;">#else</span><br /><span style="color: #ffff99;">&nbsp;&nbsp; &nbsp;trace_t&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;(*trace) (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end);</span><br /><span style="color: #ffff99;">#endif</span></code></p>
<li>Click in the&nbsp;Project title entry and type a name for your project</li>
<p>Now for the linux navlib libaries get them from <a href="https://www.kingpin.info/download/index.php?dir=kingpin/server/official/sdk/&amp;file=kingpinSDK-v121-navlib-linux-glibc-i386.zip" class="autoindex_a">kingpinSDK-v121-navlib-linux-glibc-i386.zip</a></p>
<li>Check the Folder to creat a project in and make sure it's correct and press Next.</li>
<li>In the next dialog choose as compiler:GNU GCC Compiler and make sure that Release is checked and not Debug unless you want that and click on Finish</li>
</ol>
<h3>Adding Files to the New Project</h3>
<p>Before we can add new files t the project you first need to remove the 1 file that were created to the project so we got a emtpy project.</p>
<ol>
<li>Choose from the menu Project-&gt;Remove files..</li>
<li>main.c should already be selected, press OK</li>
<li>A new confirmation dialoog will start, press Yes</li>
<li>The files main.c are still there you probably want to deleted them in an [https://en.wikipedia.org/wiki/File_manager File Manager], so you don't&nbsp;accidently add them.</li>
</ol>
<p>Now that we have our project and workspace, we need to add id's [https://www.kingpin.info/download/index.php?dir=kingpin/server/unofficial/sdk/linux/&amp;file=Linux_SDK_121.zip Kingpin Linux SDK source] files to the project.</p>
<ol>
<li>Create a new folder in your project directory called "Source"</li>
<li>Copy the [https://www.kingpin.info/download/index.php?dir=kingpin/server/unofficial/sdk/linux/&amp;file=Linux_SDK_121.zip Kingpin Linux SDK source] files to this directory</li>
<li>Under the menu Project-&gt;Add Files..</li>
<li>Change to the source directory you just created</li>
<li>Select all the *.c and *.h files from the Kingpin source (make sure you don't add main.cpp and main.h if you have not deleted them)</li>
<li>and click Open.</li>
</ol><hr style="height: 2px; border-width: 0; background-color: #e7c258;" />
<h3>Fixing the Compiler</h3>
<p>There still some things missing from the compiler the Kingpin SDK. Kingpin needs some NavLib files otherwise it won't compile.</p>
<ol>
<li>menu Project-&gt;Build Options...</li>
<li>Click on the Tab Linker settings</li>
<li>In the Link libaries: add the 4times the following files including path:<br />
<ul>
<ul>
<li>g_nav.o</li>
<li>g_nav.o</li>
Line 17: Line 44:
<li>g_nav_misc.o</li>
<li>g_nav_misc.o</li>
</ul>
</ul>
<p>and put them in your navlib folder.</p>
</li>
<hr style="height: 2px; border-width: 0; background-color: #e7c258;" />
</ol>
<p>If this is all to much work or gives problems you can downloaded the fixed sdk from <a href="https://www.kingpin.info/download/index.php?dir=kingpin/server/unofficial/sdk/linux/&amp;file=Linux_SDK_121.zip" target="_blank">here</a> with the makefile.</p>
<p>Next you need to fix some Compiler flags still under</p>
<p>Now you can compile sdk. There a few ways to compile the gamei386.so</p>
<ol>
<p>The best way:<br />Download this <a href="https://www.kingpin.info/download/index.php?dir=kingpin/server/unofficial/sdk/linux/&amp;file=makefile" target="_blank">makefile</a> and run make in the terminale.<br />or Download this <a href="https://www.kingpin.info/download/index.php?dir=kingpin/server/unofficial/sdk/linux/&amp;file=buildlinux_v2.zip" target="_blank">buildlinux</a> and make executable with:<br /><strong>chmod +x buildlinux</strong><br /> Or change the <a href="https://en.wikipedia.org/wiki/Chmod" target="_blank">chmod</a> to your own settings so long it's executable.<br />or type in a terminal:<br /><strong>cc -m32 -Os -ffast-math -fno-finite-math-only -fPIC -shared -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,--no-undefined *.c navlib/*.o -lm -o gamei386.so</strong><br /><br />The second way is with this <a href="https://www.kingpin.info/download/index.php?dir=kingpin/server/unofficial/sdk/linux/old/&amp;file=buildlinux_v1.zip" target="_blank">buildlinux</a> or this command line:<br /><strong>gcc *.c navlib/*.o -m32 -O2 -ffast-math -fPIC -shared -ffunction-sections -fdata-sections -Wl,--gc-sections -o gamei386.so</strong></p>
<li>menu Project-&gt;Build Options...</li>
<li>Tab Compiler settings</li>
<li>Turn on flag: Target x86 (32bit) [-m32]</li>
<li>Turn on flag: Position Independent Code [-fPIC]</li>
<li>Now it should compile 32bit atleast without any error.</li>
</ol>
</p>
<p><strong>To compile the .so with the correct name and the correct folder for example in game folder of Kingpin</strong>:</p>
<ol>
<li>menu Project-&gt;Properties...</li>
<li>Click on the Tab Build Targets</li>
<li>Output filename: bin\Release\gamei386.so</li>
<li>and click OK</li>
</ol><hr style="height: 2px; border-width: 0; background-color: #e7c258;" />
<h3>&nbsp;Download project file</h3>
<table style="width: 300px; border-collapse: collapse;" border="0">
<tr>
<td style="border-color: #e7c258; border-style: solid; border-width: 2px; text-align: center;">[https://www.kingpin.info/download/index.php?dir=kingpin/server/unofficial/sdk/linux/&amp;file=codeblock.zip Code::Blocks]</td>
</tr>
</table>

Latest revision as of 23:19, 19 February 2025

Introduction

Code::Blocks is a open-source IDE compared to Microsoft Visual Studio/Express
The good thing about open-source is that you can use it also in any OS.

Before you can do this you need to have done Compiling with Linux otherwise you files probably are not ready yet for linux.


Creating a New Project

First, we must create the project in which we are going to work:

  1. Start Code::Blocks
  2. Close any open Workspaces
  3. Choose from the menu File->New->Project..
  4. From the New From template dialog choose Projects->Shared Library and click Go.
  5. A Shared Library dialog will start, click on Next.
  6. Click in the Project title entry and type a name for your project
  7. Check the Folder to creat a project in and make sure it's correct and press Next.
  8. In the next dialog choose as compiler:GNU GCC Compiler and make sure that Release is checked and not Debug unless you want that and click on Finish

Adding Files to the New Project

Before we can add new files t the project you first need to remove the 1 file that were created to the project so we got a emtpy project.

  1. Choose from the menu Project->Remove files..
  2. main.c should already be selected, press OK
  3. A new confirmation dialoog will start, press Yes
  4. The files main.c are still there you probably want to deleted them in an File Manager, so you don't accidently add them.

Now that we have our project and workspace, we need to add id's Kingpin Linux SDK source files to the project.

  1. Create a new folder in your project directory called "Source"
  2. Copy the Kingpin Linux SDK source files to this directory
  3. Under the menu Project->Add Files..
  4. Change to the source directory you just created
  5. Select all the *.c and *.h files from the Kingpin source (make sure you don't add main.cpp and main.h if you have not deleted them)
  6. and click Open.

Fixing the Compiler

There still some things missing from the compiler the Kingpin SDK. Kingpin needs some NavLib files otherwise it won't compile.

  1. menu Project->Build Options...
  2. Click on the Tab Linker settings
  3. In the Link libaries: add the 4times the following files including path:
    • g_nav.o
    • g_nav_cells.o
    • g_nav_io.o
    • g_nav_misc.o

Next you need to fix some Compiler flags still under

  1. menu Project->Build Options...
  2. Tab Compiler settings
  3. Turn on flag: Target x86 (32bit) [-m32]
  4. Turn on flag: Position Independent Code [-fPIC]
  5. Now it should compile 32bit atleast without any error.

To compile the .so with the correct name and the correct folder for example in game folder of Kingpin:

  1. menu Project->Properties...
  2. Click on the Tab Build Targets
  3. Output filename: bin\Release\gamei386.so
  4. and click OK

 Download project file

Code::Blocks