Author Topic: Compiling C++ classes into quake3 engine (linker issues)  (Read 4411 times)

robhamilton

  • Posts: 4
  • Turrets: +0/-0
    • my ccrma homepage
Compiling C++ classes into quake3 engine (linker issues)
« on: December 28, 2007, 01:30:35 am »
Hi Tremulous folks,

This is more of an engine question than a tremulous-specific one but it applies to Trem devs too. The basic question regards linking C++ classes alongside the quake3 source C classes, specifically compiling on linux. For full disclosure, this question was also posted over at http://www.chatbear.com/unity2/6079/78,1198798504,2104/1065824/0#1

Thanks in advance.
---------------------------------

I'm working on updating delire + pix's excellent q3apd mod (http://www.selectparks.net/archive/q3apd.htm) by implementing a full version of OSC (Open Sound Control) into ioquake3 instead of the more limited PD-based FUDI protocol used in q3apd.

Off the bat, I'm working in Fedora 6, with the Planet CCRMA low latency kernel.

I'm trying to add support for the C++ based oscpack classes (http://www.audiomulch.com/~rossb/code/oscpack/) in ioq3 and am just getting used to the process of linking C and C++ classes using extern "C". Before tackling the whole oscpack set of classes, I've been babystepping, trying to get everything compiled and working with just a basic "int foo(int bar)" function in a test C++ class which I'm calling from ioq3's g_missle.c.

Basically, has anyone out there successfully linked c++ classes with ioquake3? I think I've sorted out the basic linking process, and have included my test.cpp into the standard linking processes in the ioquake3 makefile. This entailed adding the test.o file to the Q3GOBJ_ variable in the makefile, as well as adding C++ compiling rules along the order of

$(B)/baseq3/osc/%.o: $(OSCDIR)/%.cpp
$(DO_CPP)

where DO_CPP calls the g++ compiler in this manner:

DO_CPP=$(CPP) $(BASE_CPPFLAGS) -o $@ -c $<
and...
BASE_CPPFLAGS = -v -Wall

I'm now able to compile fine, which gives me hope, however, in loading ioquake3 with my mod, the game is unable to load the qagamei386.so where the file was added, seemingly because my function "foo" is seen as undefined (see below)

Loading dll file qagame.
Sys_LoadDll(/user/r/rob/data/q3/dev/ccrma-kdevelop/build/release-linux-i386/ccrma/qagamei386.so)...
Sys_LoadDll(/user/r/rob/data/q3/dev/ccrma-kdevelop/build/release-linux-i386/ccrma/qagamei386.so) failed:
"Failed loading /user/r/rob/data/q3/dev/ccrma-kdevelop/build/release-linux-i386/ccrma/qagamei386.so: /user/r/rob/data/q3/dev/ccrma-kdevelop/build/release-linux-i386/ccrma/qagamei386.so: undefined symbol: foo"


If anyone has any advice or can point me to any substantial and helpful resources for this kind of madness, it would be GREATLY appreciate.

Thanks all, Happy Holidays!

rob

p.s. (my modified makefile or classes can be posted if anyone is interested)

p.p.s (I'm running ioquake in this manner: ./ioquake3.i386 +set sv_pure 0 +set fs_game ccrma +devmap fan +set vm_ui 0 +set vm_cgame 0 +set vm_game 0 )

-----
rob hamilton
Center for Computer Research in Music and Acoustics (CCRMA)
Stanford University
http://ccrma.stanford.edu/~rob
rob hamilton
Center for Computer Research in Music and Acoustics (CCRMA)
Stanford University

robhamilton

  • Posts: 4
  • Turrets: +0/-0
    • my ccrma homepage
Re: Compiling C++ classes into quake3 engine (linker issues)
« Reply #1 on: December 30, 2007, 11:07:12 am »
[UPDATE]

For all those interested, it looks like my issues were primarily with the flags I was passing to the gcc compiler, specifically with the linking of qagamei386.so and cgamei386.so as such:

$(B)/baseq3/qagame$(ARCH).$(SHLIBEXT) : $(Q3GOBJ)
 $(CC) $(SHLIBLDFLAGS) -lstdc++ -o $@ $(Q3GOBJ)

$(B)/baseq3/cgame$(ARCH).$(SHLIBEXT) : $(Q3GOBJ)
 $(CC) $(SHLIBLDFLAGS) -lstdc++ -o $@ $(Q3GOBJ)

additionally it looks like the $(SHLIBCFLAGS) variable string is needed by g++:

DO_CPP=$(CPP) $(BASE_CPPFLAGS) $(SHLIBCFLAGS) -o $@ -c $<

I've started keeping track of my progress on the ccrma wiki at:

https://cm-wiki.stanford.edu/wiki/Q3osc

please let me know if you all have any suggestions or questions.

Best,

Rob


« Last Edit: December 30, 2007, 08:10:44 pm by robhamilton »
rob hamilton
Center for Computer Research in Music and Acoustics (CCRMA)
Stanford University

doomagent13

  • Posts: 506
  • Turrets: +18/-18
Re: Compiling C++ classes into quake3 engine (linker issues)
« Reply #2 on: January 13, 2008, 10:18:18 pm »
If you want to add C++ files to the qvms, I would guess that you would need to update/edit q3lcc.  Correct me if I am wrong, but cant g++ compile C files?  If so, what about just dropping all mentions of gcc?

BTW, I think you want to add "+set dedicated 1/2" to your command IF you are testing changes to the game qvm.