forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

C++ linking problems with new & delete operator, and oth

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
cooleyandy



Joined: 02 Jul 2005
Posts: 41

PostPosted: Mon Jul 04, 2005 3:14 pm    Post subject: C++ linking problems with new & delete operator, and oth Reply with quote

When compiling my c++ program, I've gotten some strange errors.

main.o: In function `spr_file::destroy()':
main.cpp:(.text+0x44c): undefined reference to `operator delete(void*)'
main.o: In function `spr_file::create(unsigned int)':
main.cpp:(.text+0x474): undefined reference to `operator new[](unsigned int)'
main.o: In function `spr_file::load(char*)':
main.cpp:(.text+0x5ac): undefined reference to `__srget'
main.o: In function `game::destroy_level()':
main.cpp:(.text+0x914): undefined reference to `operator delete(void*)'
main.o: In function `game::show_split_in(int, char*)':
main.cpp:(.text+0x2088): undefined reference to `operator new[](unsigned int)'
main.cpp:(.text+0x2328): undefined reference to `operator delete(void*)'
main.o: In function `game::show_split_out(int, char*)':
main.cpp:(.text+0x24b8): undefined reference to `operator new[](unsigned int)'
main.cpp:(.text+0x2860): undefined reference to `operator delete(void*)'
main.o: In function `game::show_scroll_down(int, char*)':
main.cpp:(.text+0x2904): undefined reference to `operator new[](unsigned int)'
main.cpp:(.text+0x2a5c): undefined reference to `operator delete(void*)'
main.o: In function `game::create_level(unsigned int)':
main.cpp:(.text+0x4288): undefined reference to `operator new[](unsigned int)'
main.o: In function `game::load_high_score(char*)':
main.cpp:(.text+0x4490): undefined reference to `fscanf'
main.o: In function `game::play_boss_level()':
main.cpp:(.text+0x77a0): undefined reference to `operator new[](unsigned int)'
main.cpp:(.text+0x7898): undefined reference to `operator delete(void*)'
scn320.o: In function `scnpalette::~scnpalette()':
scn320.cpp:(.text+0x14): undefined reference to `operator delete(void*)'
scn320.o: In function `scn320::~scn320()':
scn320.cpp:(.text+0x34): undefined reference to `operator delete(void*)'
scn320.cpp:(.text+0x3c): undefined reference to `operator delete(void*)'
scn320.cpp:(.text+0x58): undefined reference to `operator delete(void*)'
scn320.o:scn320.cpp:(.text+0x60): more undefined references to `operator delete(
void*)' follow
scn320.o: In function `scnpalette::scnpalette()':
scn320.cpp:(.text+0x134): undefined reference to `operator new[](unsigned int)'
scn320.o: In function `scn320::scn320(int)':
scn320.cpp:(.text+0x1d0): undefined reference to `operator new[](unsigned int)'
scn320.cpp:(.text+0x1dc): undefined reference to `operator new[](unsigned int)'
scn320.cpp:(.text+0x1f8): undefined reference to `cos'
scn320.cpp:(.text+0x234): undefined reference to `sin'

I'm not sure if it helped, but I also tried editing build.mak and using the newlib instead via "USE_NEWLIB_LIBC = 1" but I got more errors

/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(fstatr.o): In fun
ction `_fstat_r':
../../../../../newlib/libc/reent/fstatr.c:62: undefined reference to `fstat'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(openr.o): In func
tion `_open_r':
../../../../../newlib/libc/reent/openr.c:59: undefined reference to `open'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(sbrkr.o): In func
tion `_sbrk_r':
../../../../../newlib/libc/reent/sbrkr.c:60: undefined reference to `sbrk'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(timer.o): In func
tion `_times_r':
../../../../../newlib/libc/reent/timer.c:64: undefined reference to `times'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(timer.o): In func
tion `_gettimeofday_r':
../../../../../newlib/libc/reent/timer.c:108: undefined reference to `gettimeofd
ay'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(writer.o): In fun
ction `_write_r':
../../../../../newlib/libc/reent/writer.c:58: undefined reference to `write'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(closer.o): In fun
ction `_close_r':
../../../../../newlib/libc/reent/closer.c:53: undefined reference to `close'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(lseekr.o): In fun
ction `_lseek_r':
../../../../../newlib/libc/reent/lseekr.c:58: undefined reference to `lseek'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(readr.o): In func
tion `_read_r':
../../../../../newlib/libc/reent/readr.c:58: undefined reference to `read'

and this is when I used the newlib.

My questions is, are some functions not developed yet, such as the new and delete operator, and fgetc(), fscanf().
Back to top
View user's profile Send private message
beatwho



Joined: 15 Dec 2004
Posts: 28

PostPosted: Mon Jul 04, 2005 4:23 pm    Post subject: Reply with quote

I also get those errors when I use the USE_NEWLIB_LIBC = 1 option. although I too am using new and delete and never had a problem with them.

as a guess, check youre including the right headers (and linking with the right libs). Im at work so cant check at the moment if i did anything special.
Back to top
View user's profile Send private message
cooleyandy



Joined: 02 Jul 2005
Posts: 41

PostPosted: Mon Jul 04, 2005 4:53 pm    Post subject: Reply with quote

Okay, I've edited the build.mak again and found out about how to link different libraries. so now I've linked most of the libraries including the kitchen sink. I'm still however coming up with the following errors.

$ make
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -L. -L/usr/local/
pspdev/psp/sdk/lib main.o scn320.o keyboard.o sfx.o -lpspdebug -lpsplibc -lpspkernel -lstdc++ -lm -lg -lpspglue -lc -lsupc++ -liberty -o sdktest.elf
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libg.a(sbrkr.o): In function `_sbrk_r':
../../../../../newlib/libc/reent/sbrkr.c:60: undefined reference to `sbrk'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libg.a(writer.o): In function `_write_r':
../../../../../newlib/libc/reent/writer.c:58: undefined reference to `write'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libg.a(closer.o): In function `_close_r':
../../../../../newlib/libc/reent/closer.c:53: undefined reference to `close'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libg.a(fstatr.o): In fun
ction `_fstat_r':
../../../../../newlib/libc/reent/fstatr.c:62: undefined reference to `fstat'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libg.a(lseekr.o): In fun
ction `_lseek_r':
../../../../../newlib/libc/reent/lseekr.c:58: undefined reference to `lseek'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libg.a(readr.o): In func
tion `_read_r':
../../../../../newlib/libc/reent/readr.c:58: undefined reference to `read'
collect2: ld returned 1 exit status
make: *** [sdktest.elf] Error 1

Which libraries is suppose to contain the functions "lseek, read" etc...?
Back to top
View user's profile Send private message
Yardbird



Joined: 31 May 2005
Posts: 11

PostPosted: Mon Jul 04, 2005 6:49 pm    Post subject: Reply with quote

The library order is important (see also this thread).

I think you should use -lstdc++ -lc -lpspglue.
Also, according to mrbrown, you should use libpsplibc, or libc + libpspglue; not both together.

Doing this, I only have 1 error (after updating with svn):

Code:

/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libstdc++.a(pure.o):../../../../libstdc++-v3/libsupc++/pure.cc:54: undefined reference to `write'
collect2: ld returned 1 exit status
make: *** [.elf] Error 1


However, when I use -lpsplibc -lstdc++ -lc -lpspglue in this specific order (using both libpsplibc and libc, which I shouldn't do), even this last error disappears...

I would be glad if anyone can tell more about this...
Back to top
View user's profile Send private message
cooleyandy



Joined: 02 Jul 2005
Posts: 41

PostPosted: Mon Jul 04, 2005 7:08 pm    Post subject: Reply with quote

I've tried -lstdc++ -lc -lpspglue and it actually resulted in more errors

$ make
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -L. -L/usr/local/
pspdev/psp/sdk/lib main.o scn320.o keyboard.o sfx.o -lpspdebug -lstdc++ -lm -
lc -lpspglue -lpspkernel -o sdktest.elf
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(fstatr.o): In fun
ction `_fstat_r':
../../../../../newlib/libc/reent/fstatr.c:62: undefined reference to `fstat'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(openr.o): In func
tion `_open_r':
../../../../../newlib/libc/reent/openr.c:59: undefined reference to `open'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(sbrkr.o): In func
tion `_sbrk_r':
../../../../../newlib/libc/reent/sbrkr.c:60: undefined reference to `sbrk'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(signalr.o): In fu
nction `_kill_r':
../../../../../newlib/libc/reent/signalr.c:61: undefined reference to `kill'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(signalr.o): In fu
nction `_getpid_r':
../../../../../newlib/libc/reent/signalr.c:96: undefined reference to `getpid'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(timer.o): In func
tion `_times_r':
../../../../../newlib/libc/reent/timer.c:64: undefined reference to `times'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(timer.o): In func
tion `_gettimeofday_r':
../../../../../newlib/libc/reent/timer.c:108: undefined reference to `gettimeofd
ay'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(writer.o): In fun
ction `_write_r':
../../../../../newlib/libc/reent/writer.c:58: undefined reference to `write'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(closer.o): In fun
ction `_close_r':
../../../../../newlib/libc/reent/closer.c:53: undefined reference to `close'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(lseekr.o): In fun
ction `_lseek_r':
../../../../../newlib/libc/reent/lseekr.c:58: undefined reference to `lseek'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(readr.o): In func
tion `_read_r':
../../../../../newlib/libc/reent/readr.c:58: undefined reference to `read'
collect2: ld returned 1 exit status
make: *** [sdktest.elf] Error 1

*screaming and tearing hair*
Back to top
View user's profile Send private message
Yardbird



Joined: 31 May 2005
Posts: 11

PostPosted: Mon Jul 04, 2005 7:20 pm    Post subject: Reply with quote

You should update your toolchain.
When I omit the pspglue, I get the same errors as you, but with undefined references to _read, _lseek, _fstat etc. (underscore in the beginning).
-> your toolchain is older, since you don't have the underscores.
This was also mentioned in mrbrown' s post...
Back to top
View user's profile Send private message
cooleyandy



Joined: 02 Jul 2005
Posts: 41

PostPosted: Tue Jul 05, 2005 3:51 am    Post subject: Reply with quote

My current configuration is http://forums.ps2dev.org/viewtopic.php?t=2374

How do I update the toolchain? (such as what commands I should type in).
I'm a bit green on all this command line stuff.
Back to top
View user's profile Send private message
th0mas



Joined: 24 Apr 2005
Posts: 43
Location: Canada

PostPosted: Tue Jul 05, 2005 4:19 am    Post subject: Reply with quote

you're using psp-gcc. Try using psp-g++?
_________________
http://th0mas.xbox-scene.com
Back to top
View user's profile Send private message Visit poster's website
Yardbird



Joined: 31 May 2005
Posts: 11

PostPosted: Tue Jul 05, 2005 6:14 am    Post subject: Reply with quote

cooleyandy wrote:
My current configuration is http://forums.ps2dev.org/viewtopic.php?t=2374

How do I update the toolchain? (such as what commands I should type in).
I'm a bit green on all this command line stuff.


You can get new stuff from the svn repository.
But regarding the toolchain, I think the psptoolchain-20050625 is still valid; if you run toolchain.sh again, it will probably download new components -> can someone verify this, I only expect this because of this post of ooPo...
Back to top
View user's profile Send private message
cooleyandy



Joined: 02 Jul 2005
Posts: 41

PostPosted: Tue Jul 05, 2005 12:26 pm    Post subject: Reply with quote

th0mas wrote:
you're using psp-gcc. Try using psp-g++?


Tried it, same errors.


Quote:
You can get new stuff from the svn repository.
But regarding the toolchain, I think the psptoolchain-20050625 is still valid; if you run toolchain.sh again, it will probably download new components -> can someone verify this, I only expect this because of this post of ooPo...


I deleted the pspsdk folder, deleted the psp1.0+beta.tar.gz, and redownloaded the toolchain, and then followed the directions from

http://forums.ps2dev.org/viewtopic.php?t=2374

again. Same errors. Let me be a bit more detailed in what I'm compiling.
I'm compiling a program using 'make' and the project has multiple files.

main.cpp
sfx.cpp
scn320.cpp
keyboard.cpp

I've edited the MakeFile to have
main.o sfx.o scn320.o keyboard.o

I've been porting an old game and all the old compilation errors are fixed. (i.e. char far, old compiler specific funcs) but I just can't seem to get the code compiled.

Anyone who have successfully compiled a C++ program that uses new, delete, please let me know what configuration you have used (makefile and build.mak) and what libraries you included and what order you put it in.
Back to top
View user's profile Send private message
beatwho



Joined: 15 Dec 2004
Posts: 28

PostPosted: Tue Jul 05, 2005 12:44 pm    Post subject: Reply with quote

i have ported quite a bit of my c++ stuff over and it all works, but not with newlib, if i link with -lc etc it gives me the same errors. You will just have to live with libpspstdc++ or whatever its called and the sdk libc stuff. I have used new and delete and a bunch of other stuff fine with it.
Back to top
View user's profile Send private message
emigree



Joined: 09 May 2005
Posts: 5

PostPosted: Wed Jul 06, 2005 4:35 am    Post subject: Reply with quote

Yes, it seems that compiling c++ programs work if you link with -lpsplibc -lstdc++. new and delete works but if you try to use any stl stuff like string, vector or whatever you get alot of link errors.
Back to top
View user's profile Send private message
cooleyandy



Joined: 02 Jul 2005
Posts: 41

PostPosted: Wed Jul 06, 2005 8:22 am    Post subject: Reply with quote

Okay, I've finally isolated the problem. It seems if I use the function getc() or fscanf(), the errors:

/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(sbrkr.o): In func
tion `_sbrk_r':
../../../../../newlib/libc/reent/sbrkr.c:60: undefined reference to `sbrk'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(writer.o): In fun
ction `_write_r':
../../../../../newlib/libc/reent/writer.c:58: undefined reference to `write'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(closer.o): In fun
ction `_close_r':
../../../../../newlib/libc/reent/closer.c:53: undefined reference to `close'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(lseekr.o): In fun
ction `_lseek_r':
../../../../../newlib/libc/reent/lseekr.c:58: undefined reference to `lseek'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(readr.o): In func
tion `_read_r':
../../../../../newlib/libc/reent/readr.c:58: undefined reference to `read'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a(fstatr.o): In fun
ction `_fstat_r':
../../../../../newlib/libc/reent/fstatr.c:62: undefined reference to `fstat'
collect2: ld returned 1 exit status
make: *** [sdktest.elf] Error 1

occurs. I've followed the other post from tommybear and got the new and delete operator working.
Back to top
View user's profile Send private message
mrbrown



Joined: 17 Jan 2004
Posts: 1536

PostPosted: Wed Jul 06, 2005 9:18 am    Post subject: Reply with quote

Upgrade your toolchain.
Back to top
View user's profile Send private message
cooleyandy



Joined: 02 Jul 2005
Posts: 41

PostPosted: Thu Jul 07, 2005 10:37 am    Post subject: Reply with quote

I've followed opoo's directions to upgrade the toolchain with the 07-25-2005 one. Now everything besides scanf works flawlessly but I can work around it for now. Thanks MrBrown and everyone else for all the help. Yay :-)
Back to top
View user's profile Send private message
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Thu Jul 07, 2005 11:18 am    Post subject: Reply with quote

Yeah, the 07-25-2005 one will be great when its released in 19 days. :)
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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