Jump to content

Compiling SDK CodeBlocks Linux

From Kingpin Wiki
Revision as of 22:36, 19 February 2025 by FREDZ (talk | contribs) (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....")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

You should know a little bit about linux before you can do this.
Kingpin in the past only compiled under gcc 2.7.2.3 compiler.
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>
Maybe that was the Linux version that Xatrix used.
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.com/" target="_blank">Ubuntu</a> but loads faster and easyr in a <a href="https://en.wikipedia.org/wiki/VirtualBox" target="_blank">VirtualBox</a>)


If you're using <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:
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
Or download the old <a href="https://www.kingpin.info/download/index.php?dir=kingpin/server/unofficial/sdk/linux/old/&file=buildlinux_v0.zip" target="_blank">buildlinux.</a>
The command line came from Xatrix <a href="https://www.kingpin.info/download/index.php?dir=kingpin/server/official/sdk/&file=kingpinSDK-v121-navlib-linux-glibc-i386.zip" class="autoindex_a">kingpinSDK-v121-navlib-linux-glibc-i386.zip </a>in makefile.
Quite interesting to look at to know how they compiled the linux version.
But a few things have changes in the mean time also for the compiler.


First of all you need gcc. Open a terminal:
sudo apt-get install gcc
Now you all you need the libraries type next:
sudo apt-get install build-essential
This install the libraries
If you under a 64bit system you need also libc6-dev-i386:
sudo apt-get install libc6-dev-i386

Width <a href="https://www.kingpin.info/download/index.php?dir=kingpin/server/official/sdk/&file=kpsdk.zip" target="_blank">kpsdk.zip</a> there some problems you need to fix.
Unzip the gamesrc to some folder.
Make everything lowercase in the folder with <a href="https://www.kingpin.info/download/index.php?dir=kingpin/utilities/linux/&file=ccase.zip" target="_blank">ccase</a>:
chmod +x ccase
./ccase -r *

Search for every file that contains stricmp and not Q_stricmp and replace stricmp with Q_stricmp.
For example:
&&    (stricmp(self->enemy->client->pers.weapon->classname, "weapon_flamethrower") == 0))
Becomes:
&&    (Q_stricmp(self->enemy->client->pers.weapon->classname, "weapon_flamethrower") == 0))

Open g_items.c and search for:
static int    jacket_armor_index;
static int    combat_armor_index;
static int    body_armor_index;
static int    power_screen_index;
static int    power_shield_index;
and remove the static. So it says: int ????_armor_index; ???? with the correct name.

Last bit to fix gcc version gcc 2.7.2.3 open game.h and search for:
trace_t    (*trace) (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passent, int contentmask);
replace it with:
#if __linux__
    // callee_pop_aggregate_return attribute allows modern GCC to be used
    trace_t    (*trace) (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passent, int contentmask) __attribute__((callee_pop_aggregate_return(0)));
#else
    trace_t    (*trace) (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passent, int contentmask);
#endif

Next open p_client.c and search for:
trace_t    PM_trace (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)
replace it with:
#if __linux__
trace_t    __attribute__((callee_pop_aggregate_return(0))) PM_trace (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)
#else
trace_t    PM_trace (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)
#endif

 Last one open q_shared.h and search for:
trace_t        (*trace) (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end);
replace it with:
#if __linux__
    // callee_pop_aggregate_return attribute allows modern GCC to be used
    trace_t        (*trace) (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end) __attribute__((callee_pop_aggregate_return(0)));
#else
    trace_t        (*trace) (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end);
#endif

Now for the linux navlib libaries get them from <a href="https://www.kingpin.info/download/index.php?dir=kingpin/server/official/sdk/&file=kingpinSDK-v121-navlib-linux-glibc-i386.zip" class="autoindex_a">kingpinSDK-v121-navlib-linux-glibc-i386.zip</a>

  • g_nav.o
  • g_nav_cells.o
  • g_nav_io.o
  • g_nav_misc.o

and put them in your navlib folder.


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/&file=Linux_SDK_121.zip" target="_blank">here</a> with the makefile.

Now you can compile sdk. There a few ways to compile the gamei386.so

The best way:
Download this <a href="https://www.kingpin.info/download/index.php?dir=kingpin/server/unofficial/sdk/linux/&file=makefile" target="_blank">makefile</a> and run make in the terminale.
or Download this <a href="https://www.kingpin.info/download/index.php?dir=kingpin/server/unofficial/sdk/linux/&file=buildlinux_v2.zip" target="_blank">buildlinux</a> and make executable with:
chmod +x buildlinux
Or change the <a href="https://en.wikipedia.org/wiki/Chmod" target="_blank">chmod</a> to your own settings so long it's executable.
or type in a terminal:
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

The second way is with this <a href="https://www.kingpin.info/download/index.php?dir=kingpin/server/unofficial/sdk/linux/old/&file=buildlinux_v1.zip" target="_blank">buildlinux</a> or this command line:
gcc *.c navlib/*.o -m32 -O2 -ffast-math -fPIC -shared -ffunction-sections -fdata-sections -Wl,--gc-sections -o gamei386.so