GP32 Sprintf Problem


Drag

Member
Joined
Jan 11, 2004
Messages
371
Age
36
Location
USA
Website
drag.wootest.net
I feel really stupid with this problem here.

I'm using Mr.Mirko's SDK.

On my old computer, sprintf worked when I put it in a gp32 program.

Now, whenever I try to use sprintf, my compiler gives me an error that says sprintf is undeclared. If I try to include stdio.h, it gives me errors about conflicting structs.

So what do I need to include or link in order to get sprintf declared and working?
 
I'm using the arm-elf programs and stuff that come with mr.mirko's SDK.

Or at least, I was referred to them from a doc at his site.

Now, all of the example programs that use sprintf don't #include anything extra, so I'm thinking I might be missing a lib somewhere.

But I don't know how sprintf could work if you don't #include stdio.

Edit: The errors are conflicts between stdio.h (from devkit) and fileio.h (from the SDK)

I don't know what to do. I don't know why this is happening. I have the latest version of both Mr.Mirko's SDK, and devkitARM.

Maybe Bloodshed Dev-C++ is just being stupid.

Edit 2: Ok, fixed it. Apparently, if I #include <stdio.h> before I #include <gp32.h>, it'll compile fine.
 
Nice you fixed it :)

Whenever I have had to port any code to GP32 or Mr.Mirkos SDK, I REMOVE <stdio.h> and simply replace it with <fileio.h> and everything then compiles fine.
 
sprintf isn't defined if I include just fileio.h.

Is there something I'm not doing right? I mean, all of the example files with Mr.Mirko's SDK don't include stdlib.h, but they still have sprintf. And everyone makes it sound like you don't need to include anything extra to get sprintf working.

I'm just a little confused, that's all.

As long as I have the -s flag on my linker, I most likely am not going to need to worry about extra stuff in stdlib that I don't use making my program bulky.
 
Hi Drag,

You didn't says what the conflicts are between stdio.h and fileio.h, but it could be because gp32.h provides declarations, typedefs etc if stdio.h isn't included- for example, gp32.h might say something like
Code:
#ifndef FILE
#define FILE something
#endif
which provides a default definition of FILE so that the rest of gp32.h will not give missing symbol errors. It's like the programmer of gp32.h saying "Well, if the standard things aren't defined, then I'll define them so my code won't break". This works sometimes but, as you've seen, doesn't work other times.

In general, if you're going to include the standard headers like for example stdio.h, stdlib.h, and math.h, you should include them first, before any other headers. And as you said, putting stdio.h first made the program compile.

A couple of other things: I don't know how replacing stdio.h with fileio.h makes everything work as pea said, but perhaps pea's programs use file I/O but not the other things that stdio provides, like sprintf.

Your comment about mirko's programs not including stdlib.h but still using sprintf is a bit confusing - did you mean to say stdio.h? In any case, I'm not familiar with mirko's sdk so I can't tell you how it works. You can guarantee, however, that somewhere in the #included files will be a prototype for sprintf.

And finally, putting -s on the linker just strips debugging symbols from the final program, which will indeed make it smaller. But it has nothing to do with including "extra stuff in stdlib", because the standard libraries are designed to make sure that only the needed parts are linked in. It won't be stdlib making your program bulky!
 
Back
Top