odd c++ error

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
Thanhda
Posts: 331
Joined: Sat Apr 09, 2005 2:08 am
Location: Canada
Contact:

odd c++ error

Post by Thanhda »

alright, i've been looking around to see if people have had this same problem, and i've notice that people have. but no one really answers there question. my problem is that it cant seem to instantiate a new object into my main. basically i can create a class but when i type "testClass *test = new testClass" it doesnt seem to work. if i type "testClass *test;" it compiles. but cant access any of the members of the class.

heres what happens when i create a 'new' object

Code: Select all

psp-g++ -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -fno-exceptions -fno-rtti   -c -o main.o main.cpp
main.cpp: In function ‘int main(int, char**)’:
main.cpp:40: warning: unused variable ‘TestObj’
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall  -L. -L/usr/local/pspdev/psp/sdk/lib   main.o me.o  -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspuser -lpspkernel -o mebasic.elf
main.o: In function `main':
main.cpp:(.text+0x18): undefined reference to `operator new(unsigned int)'
collect2: ld returned 1 exit status
make: *** [mebasic.elf] Error 1
i used the "me" demo to try this. also renamed the file to main.cpp

Code: Select all

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <pspdisplay.h>
#include <stdlib.h>
#include <string.h>

/* Define the module info section */
PSP_MODULE_INFO&#40;"mebasic", 0, 1, 1&#41;;

/* Define the main thread's attribute value &#40;optional&#41; */
PSP_MAIN_THREAD_ATTR&#40;0&#41;;

/* Define printf, just to make typing easier */
#define printf  pspDebugScreenPrintf

void me_run&#40;void&#41;;
void me_end&#40;void&#41;;

class testClass 
&#123;
public&#58;
   int num;
&#125;;

int main&#40;int argc, char *argv&#91;&#93;&#41;
&#123;
        SceCtrlData ctl;
        testClass* test = new TestClass;

        pspDebugScreenInit&#40;&#41;;

        sceCtrlSetSamplingCycle&#40;0&#41;;
        sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_DIGITAL&#41;;

        /* Copy our small program into the ME reset vector */
        //memcpy&#40;&#40;void *&#41;0xbfc00040, me_run, &#40;int&#41;&#40;me_end - me_run&#41;&#41;;
        sceKernelDcacheWritebackInvalidateAll&#40;&#41;;

        sceSysregMeResetEnable&#40;&#41;;
        sceSysregMeBusClockEnable&#40;&#41;;
        sceSysregMeResetDisable&#40;&#41;;
        sceSysregVmeResetDisable&#40;&#41;;
        while&#40;1&#41;
        &#123;
                volatile u32 *count = &#40;u32*&#41; 0xBFC00060;

                pspDebugScreenSetXY&#40;0, 0&#41;;
                pspDebugScreenPrintf&#40;"ME Basic Example, press Home to exit\n"&#41;;
                sceKernelDcacheWritebackInvalidateAll&#40;&#41;;
                pspDebugScreenPrintf&#40;"ME Counter&#58; %08x\n", *count&#41;;
                sceCtrlReadBufferPositive&#40;&ctl, 1&#41;;
                if&#40;ctl.Buttons & PSP_CTRL_HOME&#41;
                &#123;
                        sceKernelExitGame&#40;&#41;;
                &#125;

                sceDisplayWaitVblankStart&#40;&#41;;
        &#125;

        return 0;
&#125;
the makefile if the same as it was default
There are 10 types of people in the world: Those who understand binary, and those who don't...
User avatar
lantus
Posts: 10
Joined: Tue May 10, 2005 12:09 pm

Post by lantus »

things may have changed but try linking with -lstdc++
xSnes9x - Snes9x Emulation for Xbox Consoles
User avatar
Thanhda
Posts: 331
Joined: Sat Apr 09, 2005 2:08 am
Location: Canada
Contact:

Post by Thanhda »

get errors. when i compile it still. but this time even more.

Code: Select all

&#91;root@localhost basic&#93;# psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall  -L. -L/usr/local/pspdev/psp/sdk/lib main.o me.o  -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspuser -lpspkernel -lstdc++ -o mebasic.elf

/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;eh_personality.o&#41;&#58; In function `base_of_encoded_value'&#58;
/tmp/pspdev/gcc-4.0.1/libstdc++-v3/../gcc/unwind-pe.h&#58;122&#58; undefined reference to `abort'
/tmp/pspdev/gcc-4.0.1/libstdc++-v3/../gcc/unwind-pe.h&#58;122&#58; undefined reference to `abort'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;eh_personality.o&#41;&#58; In function `read_encoded_value_with_base'&#58;
/tmp/pspdev/gcc-4.0.1/libstdc++-v3/../gcc/unwind-pe.h&#58;259&#58; undefined reference to `abort'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;eh_personality.o&#41;&#58; In function `get_ttype_entry'&#58;
/tmp/pspdev/gcc-4.0.1/libstdc++-v3/../gcc/unwind-pe.h&#58;90&#58; undefined reference to `abort'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;eh_terminate.o&#41;&#58;../../../../libstdc++-v3/libsupc++/eh_terminate.cc&#58;44&#58; undefined reference to `abort'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;eh_terminate.o&#41;&#58;../../../../libstdc++-v3/libsupc++/eh_terminate.cc&#58;46&#58; more undefined references to `abort' follow
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;vterminate.o&#41;&#58;../../../../libstdc++-v3/libsupc++/vterminate.cc&#58;69&#58; undefined reference to `fwrite'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;vterminate.o&#41;&#58;../../../../libstdc++-v3/libsupc++/vterminate.cc&#58;71&#58; undefined reference to `fputs'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;vterminate.o&#41;&#58;../../../../libstdc++-v3/libsupc++/vterminate.cc&#58;74&#58; undefined reference to `fwrite'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;vterminate.o&#41;&#58;../../../../libstdc++-v3/libsupc++/vterminate.cc&#58;73&#58; undefined reference to `fputs'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;vterminate.o&#41;&#58;../../../../libstdc++-v3/libsupc++/vterminate.cc&#58;74&#58; undefined reference to `fwrite'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;vterminate.o&#41;&#58;../../../../libstdc++-v3/libsupc++/vterminate.cc&#58;51&#58; undefined reference to `fwrite'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;vterminate.o&#41;&#58;../../../../libstdc++-v3/libsupc++/vterminate.cc&#58;52&#58; undefined reference to `abort'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;vterminate.o&#41;&#58;../../../../libstdc++-v3/libsupc++/vterminate.cc&#58;95&#58; undefined reference to `fwrite'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;vterminate.o&#41;&#58;../../../../libstdc++-v3/libsupc++/vterminate.cc&#58;97&#58; undefined reference to `abort'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;vterminate.o&#41;&#58;../../../../libstdc++-v3/libsupc++/vterminate.cc&#58;97&#58; undefined reference to `abort'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;vterminate.o&#41;&#58;../../../../libstdc++-v3/libsupc++/vterminate.cc&#58;87&#58; undefined reference to `fwrite'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;vterminate.o&#41;&#58;../../../../libstdc++-v3/libsupc++/vterminate.cc&#58;88&#58; undefined reference to `fputs'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;vterminate.o&#41;&#58;../../../../libstdc++-v3/libsupc++/vterminate.cc&#58;89&#58; undefined reference to `fputc'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;vterminate.o&#41;&#58;../../../../libstdc++-v3/libsupc++/vterminate.cc&#58;97&#58; undefined reference to `abort'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;cp-demangle.o&#41;&#58; In function `d_identifier'&#58;
cp-demangle.c&#58;&#40;.text+0x1538&#41;&#58; undefined reference to `memcmp'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;cp-demangle.o&#41;&#58; In function `d_print_resize'&#58;
cp-demangle.c&#58;&#40;.text+0x3e18&#41;&#58; undefined reference to `realloc'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;cp-demangle.o&#41;&#58; In function `d_demangle'&#58;
cp-demangle.c&#58;&#40;.text+0x8fd8&#41;&#58; undefined reference to `strncmp'
cp-demangle.c&#58;&#40;.text+0x9268&#41;&#58; undefined reference to `strcat'
/usr/local/pspdev/lib/gcc/psp/4.0.1/../../../../psp/lib/libstdc++.a&#40;cp-demangle.o&#41;&#58; In function `__cxa_demangle'&#58;
cp-demangle.c&#58;&#40;.text+0x95d4&#41;&#58; undefined reference to `strcpy'
/usr/local/pspdev/lib/gcc/psp/4.0.1/libgcc.a&#40;unwind-dw2.o&#41;&#58; In function `base_of_encoded_value'&#58;
../../gcc/unwind-pe.h&#58;122&#58; undefined reference to `abort'
../../gcc/unwind-pe.h&#58;122&#58; undefined reference to `abort'
/usr/local/pspdev/lib/gcc/psp/4.0.1/libgcc.a&#40;unwind-dw2.o&#41;&#58; In function `read_encoded_value_with_base'&#58;
../../gcc/unwind-pe.h&#58;259&#58; undefined reference to `abort'
/usr/local/pspdev/lib/gcc/psp/4.0.1/libgcc.a&#40;unwind-dw2.o&#41;&#58; In function `_Unwind_GetGR'&#58;
../../gcc/unwind-dw2.c&#58;146&#58; undefined reference to `abort'
/usr/local/pspdev/lib/gcc/psp/4.0.1/libgcc.a&#40;unwind-dw2.o&#41;&#58; In function `_Unwind_SetGR'&#58;
../../gcc/unwind-dw2.c&#58;182&#58; undefined reference to `abort'
/usr/local/pspdev/lib/gcc/psp/4.0.1/libgcc.a&#40;unwind-dw2.o&#41;&#58;../../gcc/unwind-dw2.c&#58;947&#58; more undefined references to `abort' follow
collect2&#58; ld returned 1 exit status

There are 10 types of people in the world: Those who understand binary, and those who don't...
cooleyandy
Posts: 41
Joined: Sat Jul 02, 2005 10:12 am

Post by cooleyandy »

you might want to try reordering the libraries. This is what I used in my build.mak

# Link with following default libraries. Other libraries should be specified in the $(LIBS) variable.
# TODO: This library list needs to be generated at configure time.
PSPSDK_LIBS = -lpspdebug -lpsppower -lpspdisplay -lpspge -lpspctrl -lpspaudiolib -lpspaudio -lpspsdk
LIBS := -lstdc++ -lpng -lmad -lz -lm
LIBS := $(LIBS) $(PSPSDK_LIBS) $(PSPSDK_LIBC_LIB) -lpspuser -lpspkernel

just remove any of the psp libraries you don't use.
Post Reply