GP32 c++ with gp32 ??


tuskenraider2k

Certified Guru
Joined
Nov 1, 2002
Messages
117
Hi there'

I've just tried to use a simple class with the dev-kit from gamepark.
- I tried to use one in the gpmain.c, but there we are not able to define classes there..
- Then I created a simple cpp & h file
Now he compiles the files just fine but in the linking phase, he complains that the function "extern void RunLoop()" does not exists

(I used the 'ex001.dsw' example)

Is it possible to use c++ here??

Thanx'
 
Last edited by a moderator:
What are you using as your compiler? If you are using one of the GNU derivatives, you make need to edit your makefile and change your compiler from gcc to g++ to compile C++ code correctly. That worked for me without a hitch.

Oops.. looks like the .dsw means you must be using VC++.. not sure if I have anything to say about that if it is the case.
 
Is there any way to use gcc with // comment support? I keep inadvertently using // comments as C++ is my usual language, but I want the speed of C. Any options/flags?
 
In your friendly (hmm hmm) Makefile ;-). All the paramaters, config, setup, init are usually there. Just need to decypher the langage ;-). (something Makefile can be a real pain, especially if you arent the one who wrote it in the first place).
 
tuskenraider2k posted on May 20 2003 said:
Now he compiles the files just fine but in the linking phase, he complains that the function "extern void RunLoop()" does not exists

(I used the 'ex001.dsw' example)

Is it possible to use c++ here??
i am using the visual c++ environment for debugging, (although it does tend to lock your computer if you step through too many lines of code at once ... bloody annoying!), and then i compile to gcc later when i think everything is working...

i also find it easier to program in c++ these days so i came up against the same problem as you

the problem is mixing c and c++, you need to add something like this in your header file...

runloop.h
Code:
#ifdef __cplusplus
extern "C" 
{
#endif

void RunLoop()

#ifdef __cplusplus
}
#endif

then in gpmain.c
Code:
#include "runloop.h"

void GpMain(void *arg)
{
    RunLoop();
}

hope this helps ... i should also point out that using the fake win32 environment and then later compiling for gcc and testing on the emulator or the real hardware may not be such a great idea...

i am frequently finding that my game runs fine in the win32 build, but when i compile in gcc the game doesn't behave the same and it takes me ages to track down what the problem is.

problems range from ... alignment, unused virtual functions, structure constructures being ignored, memory initialisation, scope of for loops ... and the list goes on

thanks for the // compiler switch Rico, did it work?

also having to define all your variables at the start of a function in c is annoying

can't live without my c++! [flame on] :lol:
 
Last edited by a moderator:
Rico posted on May 20 2003 said:
Is there any way to use gcc with // comment support? I keep inadvertently using // comments as C++ is my usual language, but I want the speed of C. Any options/flags?
Yeah, that is one of my biggest issues aswell. Writing plain C I can do, remembering to comment with
/* comment */
instead of
// comment
is something I just can't learn to do. I've had to recompile MANY times just because I had commented something with C++ style.
If you get that compiler switch working, please share the info on where to put it in the makefile etc.
 
Last edited by a moderator:
Noone who has figured out how to get the // comments working with devkitadv?
I tried pasting the -Wp,-lang-c-c++-comments line in various places in my makefiles, but no luck.
 
Add it to gp32.mk (devkitadv root). In CFLAGS, replace
Code:
  -O3 \
  -mstructure-size-boundary=8

with

Code:
  -O3 \
  -Wp,-lang-c-c++-comments \
  -mstructure-size-boundary=8
 
Last edited by a moderator:
Strange, I can't get it working, I get the same error as before when I tried adding it:

cc1.exe: Unrecognized option `-lang-c-c++-comments'
 
Perhaps there are other options that conflict with this, although that doesn't seem logical. Sorry I couldn't give you a solution.
 
Sdw posted on May 29 2003 said:
cc1.exe: Unrecognized option `-lang-c-c++-comments'
gcc no longer recognizes -lang as it interfered with another command line switch

So, this is a workaround:

First, go to http://www.student.northpark.edu/pemente/sed/#ssed and download sed-3.59.zip. Extract that file to the bin directory where make is located. Rename it to just sed.exe.

Now, to fix the C++ style comments do:

sed "s?//(.*)?/*\1 */?" filename.c > newfilename.c

so for gpmain.c I do:

sed "s?//(.*)?/*\1 */?" gpmain.c > gpmainNEW.c

I then load up gpmainNEW.c and verify that it looks ok. Then just save over the original gpmain.c

Hope that helps.
 
Last edited by a moderator:
Yes that will work as long as there is no '//' in a string literal in the code. I actually did mention that sed script on #gp32(dev)...thanks for posting it on tha boards.
 
Back
Top