lfnetwork.com mark read register faq members calendar

Thread: [QuickFix/Guide] Compiling on Linux using GCC
Thread Tools Display Modes
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Old 05-17-2010, 08:51 PM   #1
TrippHop
Lurker
 
Join Date: Dec 2009
Posts: 5
Exclamation [QuickFix/Guide] Compiling on Linux using GCC

For this guide we will be using GCC which is a free C compiler for Linux.
Also this guide is kind of a work in progress, as I am a new user of linux, GCC, and makefiles.

The first thing you need to compile on linux is access to a linux platform. Access to a linux platform could be on a server or your home computer.

For this guide I used the Ubuntu linux distro ( www.ubuntu.com ).
A very easy way to install ubuntu on your computer is to use WUBI ( http://wubi-installer.org/ ).
You can also use VirtualBox or VMWare Player to run linux on a virtual machine on your windows platform.
I don't personally like this method because it runs really slow, for me at least.

Also make sure you have the latest version of GCC with your linux distro.
With Debian/Ubuntu distros you can do "sudo apt-get install gcc" in the terminal.

Next step is to make sure you have a copy of the Jedi Academy SDK provided by Raven Software.
Here is a link to download: http://jediknight3.filefront.com/fil...y_SDK_MP;20909


Off the bat, the source files will not compile with GCC without errors, so we are going to fix them.
GCC will complain about instances of redefinition, which there are a few in the source files.


Step 1)
Find all instances of the function powf and rename it to Q_powf.

in q_shared.h:

change
Code:
float powf ( float x, int y );
to this:
Code:
float Q_powf ( float x, int y );
and in q_math.c, change this:

Code:
float powf ( float x, int y )
{
	float r = x;
	for ( y--; y>0; y-- )
		r = r * r;
	return r;
}
to this:

Code:
float Q_powf ( float x, int y )
{
	float r = x;
	for ( y--; y>0; y-- )
		r = r * r;
	return r;
}
Also if your mod is client side you will want to pay attention to cg_view.c since powf is used twice:

at line 444:
Code:
ratio = powf(dampfactor, dtime);
and line 531:
Code:
ratio = powf(dampfactor, dtime);
Step 2) Fixing bg_vehicles.h
In bg_vehicles.h there is a typedef redefinition.

Go to line 477 where you see:
Code:
// This is the implementation of the vehicle interface and any of the other variables needed. This
// is what actually represents a vehicle. -AReis.
typedef struct Vehicle_s
{
	// The entity who pilots/drives this vehicle.
	// NOTE: This is redundant (since m_pParentEntity->owner _should_ be the pilot). This makes things clearer though.
	bgEntity_t *m_pPilot;
change it to
Code:
// This is the implementation of the vehicle interface and any of the other variables needed. This
// is what actually represents a vehicle. -AReis.
#ifdef __GCC__
struct Vehicle_s
#else
typedef struct Vehicle_s
#endif
{
	// The entity who pilots/drives this vehicle.
	// NOTE: This is redundant (since m_pParentEntity->owner _should_ be the pilot). This makes things clearer though.
	bgEntity_t *m_pPilot;
and after this struct where:
Code:
	//the guy who was previously the pilot
	bgEntity_t *	m_pOldPilot;

} Vehicle_t;
change it to:
Code:
	//the guy who was previously the pilot
	bgEntity_t *	m_pOldPilot;
#ifdef __GCC__
};
#else
} Vehicle_t;
#endif

Step 3) Fixing bg_public.h
The same type of redefinition occurs in bg_public.h

Go to line 423 where you see:
Code:
typedef struct bgEntity_s
{
	entityState_t	s;
change it to:
Code:
#ifdef __GCC__
struct bgEntity_s
#else
typedef struct bgEntity_s
#endif
{
	entityState_t	s;
and after the struct where you see:
Code:
	//Data type(s) must directly correspond to the head of the gentity and centity structures

} bgEntity_t;
change it to:
Code:
	//Data type(s) must directly correspond to the head of the gentity and centity structures
#ifdef __GCC__
};
#else
} bgEntity_t;
#endif
Step 4) Fixing g_public.h
Yep, another redefinition here.

Go to line 675 where you see:
Code:
typedef struct Vehicle_s Vehicle_t;
change it to:
Code:
#ifndef __GCC__
typedef struct Vehicle_s Vehicle_t;
#endif
Step 5) Fixing bg_pmove.c

Go to line 712 where you see:
Code:
// Following couple things don't belong in the DLL namespace!
#ifdef QAGAME
typedef struct gentity_s gentity_t;
gentity_t *G_PlayEffectID(const int fxID, vec3_t org, vec3_t ang);
#endif
change this to:
Code:
// Following couple things don't belong in the DLL namespace!
#ifdef QAGAME
#ifndef __GCC__
typedef struct gentity_s gentity_t;
#endif
gentity_t *G_PlayEffectID(const int fxID, vec3_t org, vec3_t ang);
#endif
Step 6) Fixing g_ICARUScb.c

Go to line 30 where:
Code:
#ifndef _XBOX
#ifndef __linux__
enum
{

	TK_EOF = -1,
	TK_UNDEFINED,
	TK_COMMENT,
change it to:
Code:
#ifndef _XBOX
//#ifndef __linux__
#if defined(__linux__) && defined(__GCC__) || !defined(__linux__)
enum
{
	TK_EOF = -1,
	TK_UNDEFINED,
	TK_COMMENT,
Step 7) Fixing g_main.c

Go to line 500 where:
Code:
#include "../namespace_begin.h"
#ifdef __linux__
extern "C" {
#endif
change it to:
Code:
#include "../namespace_begin.h"
//#ifdef __linux__
#if defined(__linux__) && !defined(__GCC__)
extern "C" {
#endif
and after that function, change:
Code:
}
#ifdef __linux__
}
#endif
to:
Code:
}
//#ifdef __linux__
#if defined(__linux__) && !defined(__GCC__)
}
#endif
Okay that ends the editing of the source files. Now it is time to create the Makefile.
Makefiles provide a convenient means to building source files into executables or shared libraries.

Go to the codemp/game directory and inside it make a file named "Makefile".

then just copy this stuff into the makefile and save it:
Code:
#
# Linux Makefile for GCC for Jedi Academy SDK
#


# === Variables ===

# Compiler - GCC
CC = gcc

# Compiler Flags
# -D<name> ( Used to make a define like #define mydefine )
# -w ( disable warnings )
# -I<include path>  used to include headers
# -fPIC ( this flag is necessary to build shared libraries )
CFLAGS = -I../qcommon -I../server -I../icarus -I../ghoul2 -fPIC -DFINAL_BUILD -DMISSION_PACK -DQAGAME -D_JK2 -D__linux__ -D__GCC__ -w

# Target file
TARGET = jampgamei386.so

# Object Files
OFILES = 	ai_main.o ai_util.o ai_wpnav.o AnimalNPC.o \
		bg_g2_utils.o bg_lib.o bg_misc.o bg_panimate.o \
		bg_pmove.o bg_saber.o bg_saberLoad.o bg_saga.o \
		bg_slidemove.o bg_vehicleLoad.o bg_weapons.o \
		FighterNPC.o g_active.o g_arenas.o g_bot.o \
		g_client.o g_cmds.o g_combat.o g_exphysics.o \
		g_ICARUScb.o g_items.o g_log.o g_main.o g_mem.o \
		g_misc.o g_missile.o g_mover.o g_nav.o g_navnew.o \
		g_object.o g_saga.o g_session.o g_spawn.o g_strap.o \
		g_svcmds.o g_target.o g_team.o g_timer.o g_trigger.o \
		g_turret.o g_turret_G2.o g_utils.o g_vehicles.o \
		g_vehicleTurret.o g_weapon.o NPC.o NPC_AI_Atst.o \
		NPC_AI_Default.o NPC_AI_Droid.o NPC_AI_GalakMech.o \
		NPC_AI_Grenadier.o NPC_AI_Howler.o NPC_AI_ImperialProbe.o \
		NPC_AI_Interrogator.o NPC_AI_Jedi.o NPC_AI_Mark1.o \
		NPC_AI_Mark2.o NPC_AI_MineMonster.o NPC_AI_Rancor.o \
		NPC_AI_Remote.o NPC_AI_Seeker.o NPC_AI_Sentry.o \
		NPC_AI_Sniper.o NPC_AI_Stormtrooper.o NPC_AI_Utils.o \
		NPC_AI_Wampa.o NPC_behavior.o NPC_combat.o NPC_goal.o \
		NPC_misc.o NPC_move.o NPC_reactions.o NPC_senses.o \
		NPC_sounds.o NPC_spawn.o NPC_stats.o NPC_utils.o \
		q_math.o q_shared.o SpeederNPC.o tri_coll_test.o \
		WalkerNPC.o w_force.o w_saber.o



# === Arguments for the Makefile ===
#  typing just "make" invokes the first target ( which in this case is $(TARGET) )

$(TARGET): 	$(OFILES)
		$(CC) -shared -o $(TARGET) $(OFILES) -lm
.c.o:
	$(CC) $(CFLAGS) -c $*.c -o $*.o

# "make clean"
clean:
	rm -f $(OFILES)
	rm -f $(TARGET)
now with a terminal go to codemp/game and type "make".
This will build the shared libray jampgamei386.so which will be in codemp/game.

You can use "make clean", which will remove all the object files and the libary file in codemp/game.

This guide will probably change since im new to all this *nix stuff.
Also, fyi. I did not test this shared library on a server yet. So I am not sure if there are any runtime errors.
TrippHop is offline   you may: quote & reply,
Old 07-29-2010, 06:08 PM   #2
elraro
Lurker
 
Join Date: May 2008
Posts: 2
Loading dll file jampgame.
Sys_LoadDll(/home/jk31/base/jampgamei386.so)...
Sys_LoadDll(/home/jk31/base/jampgamei386.so) failed: "/home/jk31/base/jampgamei386.so: undefined symbol: trap_PointContents"
Sys_LoadDll(./linuxjampded/base/jampgamei386.so) failed: "./linuxjampded/base/jampgamei386.so: cannot open shared object file: Not a directory"
Resolving masterjk3.ravensoft.com
masterjk3.ravensoft.com resolved to 63.146.124.53:29060
Sending heartbeat to masterjk3.ravensoft.com
Sending heartbeat to masterjk3.ravensoft.com
Sys_Error: Sys_LoadDll(jampgame) failed dlopen() completely!


help
elraro is offline   you may: quote & reply,
Old 07-31-2010, 03:28 PM   #3
-=*Raz0r*=-
Rookie
 
-=*Raz0r*=-'s Avatar
 
Join Date: Oct 2006
Location: Australia
Posts: 243
Confirmed, the same error occurs for me. That's absurd.

EDIT: Scratch that, just add g_syscalls.o to the list and it should work (After you fix the extern "C" issue in that file the same way you did with vmMain in g_main.c)
Thanks Subaru

Though eh, I'm getting a segfault as soon as the map loads - this may just be my mod though, I haven't tested on base.

EDIT: Base works...fine...except when I connect with my windows client I get dropped to the console with "Shutting down OpenGL subsystem...ERROR: no shader files found"
Wat.


EDIT: All works fine, just had to actually START the server with sv_pure 0 (As opposed to changing + restarting...odd yah)


Many thanks to TrippHop, Xycaleth, Subaru

Last edited by -=*Raz0r*=-; 07-31-2010 at 07:20 PM.
-=*Raz0r*=- is offline   you may: quote & reply,
Old 08-01-2010, 02:52 AM   #4
TrippHop
Lurker
 
Join Date: Dec 2009
Posts: 5
Hey, sorry guys I never got around testing this to make sure it works. I will do it soon when I get my linux distro working again.

Also, FYI, the __linux__ macro is for Intel C++ Compiler Linux version which is kind of confusing in cases like these:

Code:
#include "../namespace_begin.h"
//#ifdef __linux__
#if defined(__linux__) && !defined(__GCC__)
extern "C" {
#endif
So if you were going to compile with Intel C++ Compiler you could probably be safe with defining __linux__ and without making any source changes.
TrippHop is offline   you may: quote & reply,
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Go Back   LucasForums > Network > JediKnight Series > Editing Central > JA Coding > [QuickFix/Guide] Compiling on Linux using GCC

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:00 PM.

LFNetwork, LLC ©2002-2011 - All rights reserved.
Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.