GP32 c or c++ ?


motten37

Still Fresh
Joined
Dec 26, 2003
Messages
30
Hi all,

recently got my gp32 and want to start programming for it.
I'm new to c and c++ though I've done java and other stuff before...

I've installed devkitadv and gone through ricos tutorial on setting it up and
doing a simple tilebased engine.

What I need to decide now is whether to start learning c or c++ more in-depth. As far as I can tell devkitadv is only c and not c++ - and I'm thinking I'll miss being able to do OO-stuff once I get the hang of the gp32 sdk and want to begin doing more ambitious stuff. Maybe there are other advantages to c++ compared to c as well ?

So - any advice on the c / c++ issue - and is there something available like ricos tutorial for devkitadv that will give me an environment that will build gxb / fxe files from c++ source ?

Cheers

/motten
 
Most of prog for GP32 are written in C, but you can also program with c++, so like you have already done some java, try c++ ;)
 
devkitadv has the C++ lib's. I used to use it to build ScummVM ages back.

My vote would be for C++, if you want to slip into old style C then remember all C is a subset of C++ ;). Try not to though. OO programing is SO much easier to maintain IMHO.
 
My program - GPBible - was also written in C++ using devkitadv under Linux. C++ is just C with added OOP functionality so you could start learning C and advance to C++ afterwards. But if you already have much experience with Java I'd recommend you to begin with C++ as it is much better for development. However, the GPSDK libs are C libs so the decision for or against C++ is a decision about your style of programming.
 
Sounds good - I'll go for c++ as I really dig object oriented stuff - seems more natural to me - probably because I was raised on object pascal and java.

However, I have no idea what I have to do in order to get the setup I have resulting from ricos tutorial to accept c++ instead of c...

The makefile in the testproject from the tut looks like this:


# devkitadv base dir
export CCBASE=c:/devkitadv
# User options passed to the compiler
export CUSER=-DLITTLE_ENDIAN -DGP32 -W -Wall -ansi -pedantic
include $(CCBASE)/gp32.mk
#------------------------------

all: hello.fxe

gpmain.o: gpmain.c

hello.elf: gpmain.o
$(LINK)

hello.fxe: hello.gxb

clean:
del hello.gxb hello.fxe hello.elf gpmain.o


and the includes in the .c file:

#include <stdlib.h>
#include "c:\devkitadv\arm-agb-elf\include\gp32\gpdef.h"
#include "c:\devkitadv\arm-agb-elf\include\gp32\gpstdlib.h"
#include "c:\devkitadv\arm-agb-elf\include\gp32\gpgraphic.h"
#include "gpmain.h"
#include "c:\devkitadv\arm-agb-elf\include\gp32\gpstdio.h"
#include "c:\devkitadv\arm-agb-elf\include\gp32\gpfont.h"


Can you give me a few pointers as to what to change in order to be able to do c++ and not just c with this ?

Thanks for the helping out - the gp32 community has been very friendly so far !

Cheers

/motten
 
include $(CCBASE)/gp32.mk < Look in that for the answers ;)

Just call the C++ compiler for all your C++ files.

For example you could set up the C++ compiler like this.
(This is for my own ToolChain but you could mod it for DevKitAdv)

# C++ Compiler
CXX = $(CYGWINBASE)/bin/$(COMPTYPE)g++

CPPFLAGS = $(CUSER) \
-mcpu=arm920t \
-mtune=arm920t \
-O3 \
-mstructure-size-boundary=32 \
-finline-functions \
-fomit-frame-pointer \
-mno-thumb-interwork \
-fno-exceptions \
-fno-common \
-fno-builtin \
-fshort-enums \
-ffast-math \
-fshort-double \
-fexpensive-optimizations \
-mapcs \
-I$(GPSDK)/include
-I$(CYGWINBASE)/arm-agb-elf/include
 
the makefile from the tutorial already has the line:

include $(CCBASE)/gp32.mk

and gp32.mk seems to contain the rest of the stuff you pasted...

So I made a set of .h / .cpp files containing the definition and implementation of a simple class and then included the .h file in my main .cpp file (the one from the tutorial that was originally just a .c file)...

This gives me all kind of compilation errors (copy / pasted at the end of this msg) - I don't think I understood your instructions ?

My main problem may be that I know next to nothing about c / c++ makefiles etc but if I could just get a setup that would let me compile and run my c++ proggies I wouldn't really have to bother with that as of yet ?

I changed this line in the makefile:

gpmain.o: gpmain.c

into this

gpmain.o: gpmain.cpp

which allowed me to compile and run the original files from the tutorial after changing the gpmain.c file to gpmain.cpp, the following errors showed up after including the .h file from the simple class I did:



C:\devkitadv\test>make
c:/devkitadv/bin/arm-agb-elf-gcc -DLITTLE_ENDIAN -DGP32 -W -Wall -ansi -pedanti
-mcpu=arm9tdmi -mtune=arm9tdmi -O3 -mstructure-size-boundary=32 -finline-funct
ons -fomit-frame-pointer -mno-thumb-interwork -fno-exceptions -fno-common -fno-
uiltin -fshort-enums -ffast-math -fshort-double -fexpensive-optimizations -mapc
-Ic:/devkitadv/arm-agb-elf/include/gp32 -Ic:/devkitadv/arm-agb-elf/include -c
pmain.cpp
In file included from c:/devkitadv/include/g++-v3/bits/char_traits.h:39,
from c:/devkitadv/include/g++-v3/bits/std_string.h:41,
from c:/devkitadv/include/g++-v3/string:31,
from PersonHeader.h:1,
from gpmain.cpp:15:
c:/devkitadv/include/g++-v3/bits/std_cstring.h:68: `memcpy' not declared
c:/devkitadv/include/g++-v3/bits/std_cstring.h:70: `strcpy' not declared
c:/devkitadv/include/g++-v3/bits/std_cstring.h:71: `strncpy' not declared
c:/devkitadv/include/g++-v3/bits/std_cstring.h:72: `strcat' not declared
c:/devkitadv/include/g++-v3/bits/std_cstring.h:73: `strncat' not declared
c:/devkitadv/include/g++-v3/bits/std_cstring.h:82: `memset' not declared
c:/devkitadv/include/g++-v3/bits/std_cstring.h:84: `strlen' not declared
In file included from c:/devkitadv/include/g++-v3/bits/std_string.h:41,
from c:/devkitadv/include/g++-v3/string:31,
from PersonHeader.h:1,
from gpmain.cpp:15:
c:/devkitadv/include/g++-v3/bits/char_traits.h: In static member function
`static size_t std::char_traits<char>::length(const char*)':
c:/devkitadv/include/g++-v3/bits/char_traits.h:158: `strlen' undeclared (first
use this function)
c:/devkitadv/include/g++-v3/bits/char_traits.h:158: (Each undeclared identifier

is reported only once for each function it appears in.)
c:/devkitadv/include/g++-v3/bits/char_traits.h: In static member function
`static char* std::char_traits<char>::copy(char*, const char*, long unsigned

int)':
c:/devkitadv/include/g++-v3/bits/char_traits.h:170: `memcpy' undeclared (first
use this function)
c:/devkitadv/include/g++-v3/bits/char_traits.h: In static member function
`static char* std::char_traits<char>::assign(char*, long unsigned int,
char)':
c:/devkitadv/include/g++-v3/bits/char_traits.h:174: `memset' undeclared (first
use this function)
In file included from c:/devkitadv/include/g++-v3/bits/stl_algobase.h:73,
from c:/devkitadv/include/g++-v3/bits/std_memory.h:49,
from c:/devkitadv/include/g++-v3/bits/std_string.h:43,
from c:/devkitadv/include/g++-v3/string:31,
from PersonHeader.h:1,
from gpmain.cpp:15:
c:/devkitadv/include/g++-v3/bits/std_cstdlib.h: At global scope:
c:/devkitadv/include/g++-v3/bits/std_cstdlib.h:85: `calloc' not declared
c:/devkitadv/include/g++-v3/bits/std_cstdlib.h:88: `free' not declared
c:/devkitadv/include/g++-v3/bits/std_cstdlib.h:92: `malloc' not declared
In file included from gpmain.cpp:15:
PersonHeader.h:6: parse error before `nm'
PersonHeader.h:8: `string' was not declared in this scope
PersonHeader.h:8: parse error before `)' token
PersonHeader.h:11: parse error before `)' token
PersonHeader.h:15: 'string' is used as a type, but is not defined as a type.
gpmain.cpp: In function `void GpMain(void*)':
gpmain.cpp:34: warning: unused parameter `void*arg'
make: *** [gpmain.o] Error 1


The included .h / .cpp files with the simple class have been tested without any issues using the default compiler in Dev-C++ to do a windows .exe btw...

The answers are probably obvious to anyone with a deeper knowledge of c++ etc. - whoever gets me out of this mess and started doing some c++ gp32 development earns a lifetime place close to my heart - in a manly platonic kind of way of course ;-)

Cheers

/motten "the clueless c-noob"
 
You just can't use the standard c libraries - you have to use the functions from the sdk. Don't use <string> or <stdlib>
you can only use <gpstring.h> and <gpstdlib.h>
You also have to reimplement the new and the del operator like this:

<gpnew.h>
/*#include <stdlib.h>
#include <string.h>
/*#include <stdexcept>*/
//#include <new>
/*#include <list>*/

/*#include "gp_allocator.h"*/
#include "gpmem.h"
/*#include "gpstring.h"*/

//using namespace std;

//
// The four functions overload glocal
// new & delete operators..
//

#ifndef NEW_H
#define NEW_H

void* operator new( long unsigned int size );
void* operator new[]( long unsigned int size );
void operator delete( void* todel );
void operator delete[]( void* todel );

#endif

^^^^^^
Above is taken from some code from Mr. Spiv I think....
 
and then add to some c-file (but I still don't know how this really worked):

void* operator new( long unsigned int size ){
return ::gm_malloc(size);
}

void* operator new[]( long unsigned int size ){
return ::gm_malloc(size);
}

void operator delete( void* todel ){
::gm_free(todel);
}

void operator delete[]( void* todel ){
::gm_free(todel);
}
 
Thanks - I'll try it out later and see if I can get i working. Just read your reply and was wondering:

at one point you say:

"You just can't use the standard c libraries - you have to use the functions from the sdk. Don't use <string> or <stdlib>
you can only use <gpstring.h> and <gpstdlib.h>"

then later:

"You also have to reimplement the new and the del operator like this:

<gpnew.h>
/*#include <stdlib.h>
#include <string.h>
/*#include <stdexcept>*/
//#include <new>
/*#include <list>*/

/*#include "gp_allocator.h"*/
#include "gpmem.h"
/*#include "gpstring.h"*/

//using namespace std;
"

I don't get it - I can't use <string> or <stdlib> yet these are included in the .h file for overloading new and delete ?

Cheers

/motten
 
They're commented out. At least, I hope so ... formatting appears to be screwed up. You can't nest /* */ comments for one thing.

The headers are ported from devkitadvance which might use stdlib names instead of the GP special ones.
 
refering to my coloured version of vi they are commented out :rolleyes:

well I copied the code directly from some devkitadv directory so don't blame me :p
however I was facing some trouble with memory allocation during development but it works now (at least it doesn't crash) and having no chance to debug doesn't make it easier.
 
rico - do you have some simple sample-code to clariy this... a .cpp, .h and makefile that will run with devkitadv would be of great help if possible ?

Cheers

/motten, who's getting more confused by the second...
 
contributions from other people than rico would of course be accepted as well ;-)
I know I'm being a pain - but so far the source I've found online isn't for c++ / devkitadv...

Cheers

/motten
 
Ok - seems to be working now - compiling at least. In case any other complete newbies like myself stumble upon this thread, heres what I did:

-Removed the inclusion of string in the .h file containing the class I did
-changed the line: "gpmain.o: gpmain.c" in the makefile to: "gpmain.o:
gpmain.cpp"
-renamed gpmain.c to gpmain.cpp
-included the .h file containing the declaration of my simple test class in
gpmain.cpp

ran the makefile without errors

Haven't overridden the new / delete constructors or tried actually instantiating
the class but so far so good.

Thanks again from everyone who helped out - I'll post some code once I have something vaguely interesting running.

Cheers

/motten
 
Whoops I wasn't clear on the problem; Devkitadv should compile a C++ file simply by calling it .cpp instead of .c, as you have found out. Do check the 'test' dir for stuff that compiles. Rename it (and the makfile references) to .cpp and it should still compile (hopefully) :)

FYI I haven't tweaked the constructors and it still seems to work - I seem to recall the problem being specific, for example allocating additional memory inside the constructor or something. Anyways, let me know how you get on.
 
Yup - I'm actually using the makefile and gpmain.h / gpmain.c (now .cpp) files
from your tutorial as the basis for my little testprograms...

Love this little machine - going to start out by trying to port some of the java stuff I've done to it - it'll probably be a good way of getting into the sdk and c++ in general...

Any cool demoscene stuff I should check out btw - I've already seen goatpark and test23...

Cheers

/motten
 
Anything from Sdw, Spiv or Mithris. Stuff of note includes Mithris' "I can't draw but I can fly" demo for the 15days compo (original), any of the newer stuff from 15days2, Spiv's LCD demo thing ( www.deadcoderssociety.tk ), oh, and Drunken Frogger :)
 
Back
Top