gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Problems with GBFS (and a reply from Tepples)

#2925 - Robin - Fri Feb 14, 2003 3:13 pm

Before I start, many thanks to Tepples for this package, if I can get it working it'll be most useful :)

OK, first my setup. I'm trying to use GBFS to provide script and graphics data for a generic GBA RPG engine. I'm using HAM as a development library, and VisualHAM for my IDE.

I'm trying to include gbfs.h and libgbfs.c in my main program, but when I try and build I get a load of errors like:

Quote:
In file included from main.cpp:5:
libgbfs.c: In function `const void* gbfs_get_obj(const GBFS_FILE*, const char*, u32*)':
libgbfs.c:108: cannot convert `void*' to `GBFS_ENTRY*' in assignment
libgbfs.c:102: warning: `GBFS_ENTRY*here' might be used uninitialized in this function


Now, I've never tried to code in C or C++ before (I've had a Java background) so excuse me being an utter newbie but I think my problem stems from GBFS being C code, and me trying to code in C++ (I'm trying to keep my project object oriented). gcc will compile both C and C++ right? If so, can I use C libraries like GBFS in a C++ program? Am I on completely the wrong track and there's an obvious answer? If this is impossible are there any plans to port GBFS to a C++ codebase, or any alternative packages in C++ that perform a similar function?

Sorry for all the questions, and thanks for your time ^_^

#2926 - Robin - Fri Feb 14, 2003 3:16 pm

OK, after some problems posting this I emailed the above text straight to Tepples - here's the response I got. I'll try and get this working today, but I'll leave this post up in case anyone else runs into the same problems I did.
Quote:
> OK, first my setup. I'm trying to use GBFS to provide script and
> graphics data for a generic GBA RPG engine. I'm using HAM as
> a development library, and VisualHAM for my IDE.


I have not tested GBFS with HAM, only with Devkit Advance.

> In file included from main.cpp:5:
> libgbfs.c:


Do NOT #include one .c file from another .c file or from a .cpp file.
It's a bad habit that seems most widespread among beginners who
don't know how to use the linker properly. Instead, add libgbfs.c to
your project's list of source files and put this in main.cpp:
extern "C" {
#include "gbfs.h"
}
The extern "C" part is there to mark the function prototypes in
libgbfs.h as using C calling conventions.

> but I think my problem stems from GBFS being C code, and me
> trying to code in C++ (I'm trying to keep my project object oriented).


Object orientation can be done in C; just look at GNOME.

> gcc will compile both C and C++ right? If so, can I use C libraries
> like GBFS in a C++ program?


Yes, but you'll have to compile them in separate compilation units.

Another thing you'll have to watch out for when using GBFS with C++:
GBFS returns pointers to objects as (const void *). C automatically
casts between generic pointers (void *) and specific pointers
(GBFS_ENTRY *), but C++ doesn't. You'll have to put some casts
in your code.