| View previous topic :: View next topic |
| Author |
Message |
cooleyandy
Joined: 02 Jul 2005 Posts: 41
|
Posted: Mon Jul 04, 2005 3:14 pm Post subject: C++ linking problems with new & delete operator, and oth |
|
|
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 |
|
 |
beatwho
Joined: 15 Dec 2004 Posts: 28
|
Posted: Mon Jul 04, 2005 4:23 pm Post subject: |
|
|
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 |
|
 |
cooleyandy
Joined: 02 Jul 2005 Posts: 41
|
Posted: Mon Jul 04, 2005 4:53 pm Post subject: |
|
|
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 |
|
 |
Yardbird
Joined: 31 May 2005 Posts: 11
|
Posted: Mon Jul 04, 2005 6:49 pm Post subject: |
|
|
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 |
|
 |
cooleyandy
Joined: 02 Jul 2005 Posts: 41
|
Posted: Mon Jul 04, 2005 7:08 pm Post subject: |
|
|
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 |
|
 |
Yardbird
Joined: 31 May 2005 Posts: 11
|
Posted: Mon Jul 04, 2005 7:20 pm Post subject: |
|
|
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 |
|
 |
cooleyandy
Joined: 02 Jul 2005 Posts: 41
|
Posted: Tue Jul 05, 2005 3:51 am Post subject: |
|
|
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 |
|
 |
th0mas
Joined: 24 Apr 2005 Posts: 43 Location: Canada
|
|
| Back to top |
|
 |
Yardbird
Joined: 31 May 2005 Posts: 11
|
Posted: Tue Jul 05, 2005 6:14 am Post subject: |
|
|
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 |
|
 |
cooleyandy
Joined: 02 Jul 2005 Posts: 41
|
Posted: Tue Jul 05, 2005 12:26 pm Post subject: |
|
|
| 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 |
|
 |
beatwho
Joined: 15 Dec 2004 Posts: 28
|
Posted: Tue Jul 05, 2005 12:44 pm Post subject: |
|
|
| 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 |
|
 |
emigree
Joined: 09 May 2005 Posts: 5
|
Posted: Wed Jul 06, 2005 4:35 am Post subject: |
|
|
| 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 |
|
 |
cooleyandy
Joined: 02 Jul 2005 Posts: 41
|
Posted: Wed Jul 06, 2005 8:22 am Post subject: |
|
|
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 |
|
 |
mrbrown
Joined: 17 Jan 2004 Posts: 1536
|
Posted: Wed Jul 06, 2005 9:18 am Post subject: |
|
|
| Upgrade your toolchain. |
|
| Back to top |
|
 |
cooleyandy
Joined: 02 Jul 2005 Posts: 41
|
Posted: Thu Jul 07, 2005 10:37 am Post subject: |
|
|
| 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 |
|
 |
ooPo Site Admin
Joined: 17 Jan 2004 Posts: 2032 Location: Canada
|
Posted: Thu Jul 07, 2005 11:18 am Post subject: |
|
|
| Yeah, the 07-25-2005 one will be great when its released in 19 days. :) |
|
| Back to top |
|
 |
|