 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
funkmeister
Joined: 10 May 2006 Posts: 8
|
Posted: Fri May 19, 2006 9:47 am Post subject: Compiler has an issue with strings |
|
|
I've been trying for days to get my script to compile using a simple string, but but simply refuses to. I've run it by several veteran coders, and referenced it against many websites, but everyone said it looks like it should compile. Any help is greatly appreciated.
| Code: | #include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <pspdisplay.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
PSP_MODULE_INFO("Use Strings", 0, 1, 1);
#define printf pspDebugScreenPrintf
#define RGB(r, g, b) ((r)|((g)<<8)|((b)<<16))
#define clearsc pspDebugScreenClear
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int main(void)
{
//string mystring = "text";
SetupCallbacks();
printf("Display some text %d",mystring);
sceKernelSleepThread();
return 0;
} |
The Makefile I'm using is: (I figured I'd throw in all those libs hoping one of them would work)
| Code: | TARGET = MakeString
OBJS = main.o
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LIBS = -lpspgu -lpsppower -lpng -lz -lm -lmad -lpspaudiolib -lpspaudio -lpsprtc -lpsphprm -lpspusb -lpspusbstor -lpsputility -lstdc++
LDFLAGS =
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Make String
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak |
|
|
| Back to top |
|
 |
funkmeister
Joined: 10 May 2006 Posts: 8
|
Posted: Fri May 19, 2006 9:51 am Post subject: |
|
|
Forgot two things
1) I'm aware I have the mystring line commented, I forgot to uncomment it before posting
2) the errors I get are
error: "syntax error before 'namespace'"
warning: "type defaults to 'int' declaration of 'std'"
warning: "data definition has no type or storage class"
occasionally, it refuses to recognize that <string> exists
I'm using cygwin to compile, Dev-C++ to code, and the most recent stable build of the toolchain. |
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Fri May 19, 2006 12:02 pm Post subject: |
|
|
hehe wow ...well for you all you need to do is
alter just two little thing :P
first your declaration is wrong should be
| Code: | | string mystring[] = "test"; |
this
| Code: | | printf("Display some text %d",mystring); |
into
| Code: | | printf("Display some text %s",mystring); |
notice the %s ...that means that the argument would correspond
to a string and that printf should print that argument into a string
and not an integer (%d) which you had above ...also all these
are not needed
| Code: | | LIBS = -lpspgu -lpsppower -lpng -lz -lm -lmad -lpspaudiolib -lpspaudio -lpsprtc -lpsphprm -lpspusb -lpspusbstor -lpsputility -lstdc++ |
this is fine
_________________ 10011011 00101010 11010111 10001001 10111010 |
|
| Back to top |
|
 |
funkmeister
Joined: 10 May 2006 Posts: 8
|
Posted: Fri May 19, 2006 12:22 pm Post subject: |
|
|
| Nope, that's not the problem. The code was an except from a MUCH larger program, that's why I have all the libs on the makefile. The problem is that it doesn't recognize "using". Tried recompiling both my program AND the toolchain, but no luck. |
|
| Back to top |
|
 |
PlayfulPuppy
Joined: 05 May 2006 Posts: 22
|
Posted: Fri May 19, 2006 11:13 pm Post subject: |
|
|
| dot_blank wrote: | hehe wow ...well for you all you need to do is
alter just two little thing :P
first your declaration is wrong should be
| Code: | | string mystring[] = "test"; |
|
No it shouldn't. It's a C++ string class, not a C-style string.
| Quote: |
this
| Code: | | printf("Display some text %d",mystring); |
into
| Code: | | printf("Display some text %s",mystring); |
|
Should actually be this:
| Code: | | printf("Display some text %s", mystring.c_str()); |
As for the compilation errors you're getting, try replacing this:
| Code: | | #include <string.h> |
with this:
Also make sure your file has a .CPP extension, otherwise I'm fairly sure it'll try and compile it using a C compiler (Which doesn't have the 'using' keyword nor templates). Either way, make sure MAKE is executing vs-psp-g++ instead of vs-psp-gcc. |
|
| Back to top |
|
 |
danzel
Joined: 04 Nov 2005 Posts: 182
|
Posted: Fri May 19, 2006 11:15 pm Post subject: |
|
|
If this was meant to be c++ then make sure your file is named something.cpp so that it is compiled by g++ and not gcc (you will see in the compile output which one was used)
also
| Code: | //string mystring = "text";
SetupCallbacks();
printf("Display some text %d",mystring); |
that should be:
| Code: | string mystring = "text";
SetupCallbacks();
printf("Display some text %s",mystring.c_str()); |
and change
#include <string.h>
to
#include <string>
(NOTE: I assume you want to use c++ strings, and not c char* type strings)
Danzel.
ps. one other small thing fixing what dot_blank said:
string mystring[] = "test";
that should be
char mystring[] = "test";
if you are using c and not c++ strings, in this case keep #include <string.h> |
|
| Back to top |
|
 |
funkmeister
Joined: 10 May 2006 Posts: 8
|
Posted: Sat May 20, 2006 1:20 am Post subject: |
|
|
oh...my...god....
After spending four days rearranging code, and recompiling...you're telling me my problem was the file extension?
[puts on n00b cap, draws a circle on the chalk board and put nose in it]
I was using main.c, and I'm kicking myself, since I had changed the extension to .cpp earlier, but changed it back before I attempted to implement strings since I had realized I wasn't doing anything at that point that required .cpp.
That would also explain why it would recognize <string.h>, but never <string>. Awesome, thanks everyone. |
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Sat May 20, 2006 11:43 am Post subject: |
|
|
haha this is by far the most interesting thread
just for the fact to show that the user should first
realize that this forum is for psp DEV ...keyword is DEV
meaning that you would obviously have to know what
DEV is and how to DEV ....and big oops in my enjoyment
of this thread i over saw the mystring.c_str() :)
but in the end ....file extension is key :P _________________ 10011011 00101010 11010111 10001001 10111010 |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|