strange behavior when using psp-g++ without -fno-exceptions

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

Moderators: cheriff, TyRaNiD

Post Reply
binch
Posts: 28
Joined: Tue Jul 04, 2006 4:17 pm
Location: China

strange behavior when using psp-g++ without -fno-exceptions

Post by binch »

what you guys has done to this flag? without this flag we can't find many symbols! but it's not the original purpose for this flags in g++.

Code:

#include <pspstdio.h>
#include <pspkernel.h>
#include <pspuser.h>

PSP_MODULE_INFO("Zhen Han Zi", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);

main()
{
}


psp-g++ -I. -I/usr/local/pspdev/psp/sdk/include -G0 -Wall -O2 -D_PSP_FW_VERSION=150 -G0 -Wall -O2 -L. -L/usr/local/pspdev/psp/sdk/lib t.cpp -lc -lpspgu -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o ZombieStation.elf
t.cpp:8: warning: ISO C++ forbids declaration of 'main' with no type
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_write.o): In function `_write':
../../../../../../newlib/libc/sys/psp/libcglue.c:308: undefined reference to `sceIoWrite'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_nonblocking_write':
../../../../../../newlib/libc/sys/psp/pipe.c:258: undefined reference to `sceKernelTrySendMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_write':
../../../../../../newlib/libc/sys/psp/pipe.c:234: undefined reference to `sceKernelSendMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_close':
../../../../../../newlib/libc/sys/psp/pipe.c:100: undefined reference to `sceKernelDeleteMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `pipe':
../../../../../../newlib/libc/sys/psp/pipe.c:50: undefined reference to `sceKernelCreateMsgPipe'
../../../../../../newlib/libc/sys/psp/pipe.c:70: undefined reference to `sceKernelDeleteMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_peekmsgsize':
../../../../../../newlib/libc/sys/psp/pipe.c:34: undefined reference to `sceKernelReferMsgPipeStatus'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_read':
../../../../../../newlib/libc/sys/psp/pipe.c:198: undefined reference to `sceKernelReceiveMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_nonblocking_read':
../../../../../../newlib/libc/sys/psp/pipe.c:148: undefined reference to `sceKernelTryReceiveMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_close.o): In function `_close':
../../../../../../newlib/libc/sys/psp/libcglue.c:236: undefined reference to `sceIoClose'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_fstat.o): In function `_fstat':
../../../../../../newlib/libc/sys/psp/libcglue.c:580: undefined reference to `sceIoLseek'
../../../../../../newlib/libc/sys/psp/libcglue.c:582: undefined reference to `sceIoLseek'
../../../../../../newlib/libc/sys/psp/libcglue.c:583: undefined reference to `sceIoLseek'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_lseek.o): In function `_lseek':
../../../../../../newlib/libc/sys/psp/libcglue.c:345: undefined reference to `sceIoLseek'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_read.o): In function `_read':
../../../../../../newlib/libc/sys/psp/libcglue.c:271: undefined reference to `sceIoRead'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_stat.o): In function `_stat':
../../../../../../newlib/libc/sys/psp/libcglue.c:642: undefined reference to `sceIoGetstat'
collect2: ld returned 1 exit status

Add the fno-exceptions flag then produce right result.

psp-g++ -I. -I/usr/local/pspdev/psp/sdk/include -G0 -Wall -O2 -D_PSP_FW_VERSION=150 -G0 -Wall -O2 -L. -L/usr/local/pspdev/psp/sdk/lib -fno-exceptions t.cpp -lc -lpspgu -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o ZombieStation.elf
t.cpp:8: warning: ISO C++ forbids declaration of 'main' with no type
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Every example I've seen for the PSP adds -fno-exceptions to the c++ flags. I guess now you know why.
PeterM
Posts: 125
Joined: Sat Dec 31, 2005 7:25 pm
Location: Edinburgh, UK
Contact:

Post by PeterM »

I suspect it depends on your library order when linking.

I've not always used -fno-exceptions and I've still got my C++ code to link.
http://aaiiee.wordpress.com/

I can no longer do any homebrew PSP development nor discuss PSP specific topics.
binch
Posts: 28
Joined: Tue Jul 04, 2006 4:17 pm
Location: China

Post by binch »

J.F. wrote:Every example I've seen for the PSP adds -fno-exceptions to the c++ flags. I guess now you know why.
i don't know why. every example use this flag doesn't means this way IS correct. the no-exception is used for abandon the C++ exception machnism, right? whats the relationship between the unresolved symbol and the c++ exception?

why?
binch
Posts: 28
Joined: Tue Jul 04, 2006 4:17 pm
Location: China

Post by binch »

PeterM wrote:I suspect it depends on your library order when linking.

I've not always used -fno-exceptions and I've still got my C++ code to link.
no, it's not true, the same order can be ok with linking using gcc, not g++. maybe you are compiling in g++ but linking with gcc.
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Your code and first command line compile just fine for me.
Could you add -v to the g++ command line and paste the output?
be2003
Posts: 144
Joined: Thu Apr 20, 2006 2:46 pm

Re: strange behavior when using psp-g++ without -fno-excepti

Post by be2003 »

binch wrote:what you guys has done to this flag? without this flag we can't find many symbols! but it's not the original purpose for this flags in g++.

Code:

#include <pspstdio.h>
#include <pspkernel.h>
#include <pspuser.h>

PSP_MODULE_INFO("Zhen Han Zi", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);

main()
{
}


psp-g++ -I. -I/usr/local/pspdev/psp/sdk/include -G0 -Wall -O2 -D_PSP_FW_VERSION=150 -G0 -Wall -O2 -L. -L/usr/local/pspdev/psp/sdk/lib t.cpp -lc -lpspgu -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o ZombieStation.elf
t.cpp:8: warning: ISO C++ forbids declaration of 'main' with no type
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_write.o): In function `_write':
../../../../../../newlib/libc/sys/psp/libcglue.c:308: undefined reference to `sceIoWrite'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_nonblocking_write':
../../../../../../newlib/libc/sys/psp/pipe.c:258: undefined reference to `sceKernelTrySendMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_write':
../../../../../../newlib/libc/sys/psp/pipe.c:234: undefined reference to `sceKernelSendMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_close':
../../../../../../newlib/libc/sys/psp/pipe.c:100: undefined reference to `sceKernelDeleteMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `pipe':
../../../../../../newlib/libc/sys/psp/pipe.c:50: undefined reference to `sceKernelCreateMsgPipe'
../../../../../../newlib/libc/sys/psp/pipe.c:70: undefined reference to `sceKernelDeleteMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_peekmsgsize':
../../../../../../newlib/libc/sys/psp/pipe.c:34: undefined reference to `sceKernelReferMsgPipeStatus'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_read':
../../../../../../newlib/libc/sys/psp/pipe.c:198: undefined reference to `sceKernelReceiveMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_nonblocking_read':
../../../../../../newlib/libc/sys/psp/pipe.c:148: undefined reference to `sceKernelTryReceiveMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_close.o): In function `_close':
../../../../../../newlib/libc/sys/psp/libcglue.c:236: undefined reference to `sceIoClose'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_fstat.o): In function `_fstat':
../../../../../../newlib/libc/sys/psp/libcglue.c:580: undefined reference to `sceIoLseek'
../../../../../../newlib/libc/sys/psp/libcglue.c:582: undefined reference to `sceIoLseek'
../../../../../../newlib/libc/sys/psp/libcglue.c:583: undefined reference to `sceIoLseek'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_lseek.o): In function `_lseek':
../../../../../../newlib/libc/sys/psp/libcglue.c:345: undefined reference to `sceIoLseek'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_read.o): In function `_read':
../../../../../../newlib/libc/sys/psp/libcglue.c:271: undefined reference to `sceIoRead'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_stat.o): In function `_stat':
../../../../../../newlib/libc/sys/psp/libcglue.c:642: undefined reference to `sceIoGetstat'
collect2: ld returned 1 exit status

Add the fno-exceptions flag then produce right result.

psp-g++ -I. -I/usr/local/pspdev/psp/sdk/include -G0 -Wall -O2 -D_PSP_FW_VERSION=150 -G0 -Wall -O2 -L. -L/usr/local/pspdev/psp/sdk/lib -fno-exceptions t.cpp -lc -lpspgu -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o ZombieStation.elf
t.cpp:8: warning: ISO C++ forbids declaration of 'main' with no type
its pretty cool how you are having a problem with compiling with certain flags and you didnt even post your makefile...
- be2003
blog
binch
Posts: 28
Joined: Tue Jul 04, 2006 4:17 pm
Location: China

Re: strange behavior when using psp-g++ without -fno-excepti

Post by binch »

be2003 wrote:
binch wrote:what you guys has done to this flag? without this flag we can't find many symbols! but it's not the original purpose for this flags in g++.

Code:

#include <pspstdio.h>
#include <pspkernel.h>
#include <pspuser.h>

PSP_MODULE_INFO("Zhen Han Zi", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);

main()
{
}


psp-g++ -I. -I/usr/local/pspdev/psp/sdk/include -G0 -Wall -O2 -D_PSP_FW_VERSION=150 -G0 -Wall -O2 -L. -L/usr/local/pspdev/psp/sdk/lib t.cpp -lc -lpspgu -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o ZombieStation.elf
t.cpp:8: warning: ISO C++ forbids declaration of 'main' with no type
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_write.o): In function `_write':
../../../../../../newlib/libc/sys/psp/libcglue.c:308: undefined reference to `sceIoWrite'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_nonblocking_write':
../../../../../../newlib/libc/sys/psp/pipe.c:258: undefined reference to `sceKernelTrySendMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_write':
../../../../../../newlib/libc/sys/psp/pipe.c:234: undefined reference to `sceKernelSendMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_close':
../../../../../../newlib/libc/sys/psp/pipe.c:100: undefined reference to `sceKernelDeleteMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `pipe':
../../../../../../newlib/libc/sys/psp/pipe.c:50: undefined reference to `sceKernelCreateMsgPipe'
../../../../../../newlib/libc/sys/psp/pipe.c:70: undefined reference to `sceKernelDeleteMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_peekmsgsize':
../../../../../../newlib/libc/sys/psp/pipe.c:34: undefined reference to `sceKernelReferMsgPipeStatus'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_read':
../../../../../../newlib/libc/sys/psp/pipe.c:198: undefined reference to `sceKernelReceiveMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_nonblocking_read':
../../../../../../newlib/libc/sys/psp/pipe.c:148: undefined reference to `sceKernelTryReceiveMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_close.o): In function `_close':
../../../../../../newlib/libc/sys/psp/libcglue.c:236: undefined reference to `sceIoClose'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_fstat.o): In function `_fstat':
../../../../../../newlib/libc/sys/psp/libcglue.c:580: undefined reference to `sceIoLseek'
../../../../../../newlib/libc/sys/psp/libcglue.c:582: undefined reference to `sceIoLseek'
../../../../../../newlib/libc/sys/psp/libcglue.c:583: undefined reference to `sceIoLseek'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_lseek.o): In function `_lseek':
../../../../../../newlib/libc/sys/psp/libcglue.c:345: undefined reference to `sceIoLseek'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_read.o): In function `_read':
../../../../../../newlib/libc/sys/psp/libcglue.c:271: undefined reference to `sceIoRead'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_stat.o): In function `_stat':
../../../../../../newlib/libc/sys/psp/libcglue.c:642: undefined reference to `sceIoGetstat'
collect2: ld returned 1 exit status

Add the fno-exceptions flag then produce right result.

psp-g++ -I. -I/usr/local/pspdev/psp/sdk/include -G0 -Wall -O2 -D_PSP_FW_VERSION=150 -G0 -Wall -O2 -L. -L/usr/local/pspdev/psp/sdk/lib -fno-exceptions t.cpp -lc -lpspgu -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o ZombieStation.elf
t.cpp:8: warning: ISO C++ forbids declaration of 'main' with no type
its pretty cool how you are having a problem with compiling with certain flags and you didnt even post your makefile...
why i need to use makefile when i am doing something debug work?
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

I just built an up-to-date toolchain and retested, there is definitely nothing wrong with pspsdk in this regard. With both -fexceptions and -fno-exceptions your example code compiles just fine. If you're not going to help by providing what we ask for, well, don't expect an answer.
binch
Posts: 28
Joined: Tue Jul 04, 2006 4:17 pm
Location: China

Post by binch »

jimparis wrote:I just built an up-to-date toolchain and retested, there is definitely nothing wrong with pspsdk in this regard. With both -fexceptions and -fno-exceptions your example code compiles just fine. If you're not going to help by providing what we ask for, well, don't expect an answer.
sure, i run this and get the result, my toolchain is NOT up to date, because i get it from http://www.oopo.net/consoledev/:

psp-g++ -v
Using built-in specs.
Target: psp
Configured with: ../configure --prefix=/usr/local/pspdev --target=psp --enable-languages=c,c++ --with-newlib --enable-cxx-flags=-G0
Thread model: single
gcc version 4.1.0 (PSPDEV 20060507)
binch
Posts: 28
Joined: Tue Jul 04, 2006 4:17 pm
Location: China

Post by binch »

and with uname -a

Linux binch.example.com 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux

but i don't think there are any problems with the host env.
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Add -v to the command line. We need to see the output when it's actually building your program and failing.

You're building with gcc 4.1.0. The normal svn toolchain still uses 4.0.2 and works fine. Perhaps this is a regression in 4.1.0 that needs to be addressed. Any ideas ooPo?
binch
Posts: 28
Joined: Tue Jul 04, 2006 4:17 pm
Location: China

Post by binch »

jimparis wrote:Add -v to the command line. We need to see the output when it's actually building your program and failing.
what do you mean? how to add the -v to the command line, the -v option is used for version, but i have showed this to you all.
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

You have a command line that you're using to compile the program. Add -v to that.

Code: Select all

psp-g++ -v -I. -I/usr/local/pspdev/psp/sdk/include -G0 -Wall -O2 -D_PSP_FW_VERSION=150 -G0 -Wall -O2 -L. -L/usr/local/pspdev/psp/sdk/lib t.cpp -lc -lpspgu -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o ZombieStation.elf
binch
Posts: 28
Joined: Tue Jul 04, 2006 4:17 pm
Location: China

Post by binch »

Hi jimparis,

thanks for your help!

psp-g++ -v -I. -I/usr/local/pspdev/psp/sdk/include -G0 -Wall -O2 -D_PSP_FW_VERSION=150 -G0 -Wall -O2 -L. -L/usr/local/pspdev/psp/sdk/lib t.cpp -lc -lpspgu -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o ZombieStation.elf
Using built-in specs.
Target: psp
Configured with: ../configure --prefix=/usr/local/pspdev --target=psp --enable-languages=c,c++ --with-newlib --enable-cxx-flags=-G0
Thread model: single
gcc version 4.1.0 (PSPDEV 20060507)
/usr/local/pspdev/libexec/gcc/psp/4.1.0/cc1plus -quiet -v -I. -I/usr/local/pspdev/psp/sdk/include -DPSP=1 -D__psp__=1 -D_PSP=1 -D_PSP_FW_VERSION=150 t.cpp -G0 -G0 -quiet -dumpbase t.cpp -auxbase t -O2 -O2 -Wall -Wall -version -o /tmp/ccuZSyxU.s
ignoring nonexistent directory "/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/sys-include"
#include "..." search starts here:
#include <...> search starts here:
.
/usr/local/pspdev/psp/sdk/include
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/psp
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../include/c++/4.1.0/backward
/usr/local/pspdev/lib/gcc/psp/4.1.0/include
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/include
End of search list.
GNU C++ version 4.1.0 (PSPDEV 20060507) (psp)
compiled by GNU C version 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5).
GGC heuristics: --param ggc-min-expand=81 --param ggc-min-heapsize=96914
Compiler executable checksum: 15e6552522752d2f31558c4d025d24c8
t.cpp:1: warning: ISO C++ forbids declaration of 'main' with no type
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/bin/as -G0 -G0 -EL -O2 -no-mdebug -mabi=eabi -v -mno-pdr -o /tmp/ccQJyjsO.o /tmp/ccuZSyxU.s
GNU assembler version 2.16.1 (psp) using BFD version 2.16.1 (PSPDEV 20060116)
/usr/local/pspdev/libexec/gcc/psp/4.1.0/collect2 -EL -G0 -G0 -o ZombieStation.elf /usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/crt0.o /usr/local/pspdev/lib/gcc/psp/4.1.0/crti.o /usr/local/pspdev/lib/gcc/psp/4.1.0/crtbegin.o -L. -L/usr/local/pspdev/psp/sdk/lib -L/usr/local/pspdev/lib/gcc/psp/4.1.0 -L/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib /tmp/ccQJyjsO.o -lpspgu -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -lstdc++ -lm -lc -lgcc -lgcc /usr/local/pspdev/lib/gcc/psp/4.1.0/crtend.o /usr/local/pspdev/lib/gcc/psp/4.1.0/crtn.o
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_write.o): In function `_write':
../../../../../../newlib/libc/sys/psp/libcglue.c:308: undefined reference to `sceIoWrite'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_nonblocking_write':
../../../../../../newlib/libc/sys/psp/pipe.c:258: undefined reference to `sceKernelTrySendMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_write':
../../../../../../newlib/libc/sys/psp/pipe.c:234: undefined reference to `sceKernelSendMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_close':
../../../../../../newlib/libc/sys/psp/pipe.c:100: undefined reference to `sceKernelDeleteMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `pipe':
../../../../../../newlib/libc/sys/psp/pipe.c:50: undefined reference to `sceKernelCreateMsgPipe'
../../../../../../newlib/libc/sys/psp/pipe.c:70: undefined reference to `sceKernelDeleteMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_peekmsgsize':
../../../../../../newlib/libc/sys/psp/pipe.c:34: undefined reference to `sceKernelReferMsgPipeStatus'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_read':
../../../../../../newlib/libc/sys/psp/pipe.c:198: undefined reference to `sceKernelReceiveMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(pipe.o): In function `__psp_pipe_nonblocking_read':
../../../../../../newlib/libc/sys/psp/pipe.c:148: undefined reference to `sceKernelTryReceiveMsgPipe'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_close.o): In function `_close':
../../../../../../newlib/libc/sys/psp/libcglue.c:236: undefined reference to `sceIoClose'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_fstat.o): In function `_fstat':
../../../../../../newlib/libc/sys/psp/libcglue.c:580: undefined reference to `sceIoLseek'
../../../../../../newlib/libc/sys/psp/libcglue.c:582: undefined reference to `sceIoLseek'
../../../../../../newlib/libc/sys/psp/libcglue.c:583: undefined reference to `sceIoLseek'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_lseek.o): In function `_lseek':
../../../../../../newlib/libc/sys/psp/libcglue.c:345: undefined reference to `sceIoLseek'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_read.o): In function `_read':
../../../../../../newlib/libc/sys/psp/libcglue.c:271: undefined reference to `sceIoRead'
/usr/local/pspdev/lib/gcc/psp/4.1.0/../../../../psp/lib/libc.a(_stat.o): In function `_stat':
../../../../../../newlib/libc/sys/psp/libcglue.c:642: undefined reference to `sceIoGetstat'
collect2: ld returned 1 exit status
binch
Posts: 28
Joined: Tue Jul 04, 2006 4:17 pm
Location: China

Post by binch »

jimparis wrote:I just built an up-to-date toolchain and retested, there is definitely nothing wrong with pspsdk in this regard. With both -fexceptions and -fno-exceptions your example code compiles just fine. If you're not going to help by providing what we ask for, well, don't expect an answer.
could you please tell me how you bulid it, you didn't get the build script from oopo.net, right?
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

OK, this is the usual library-link-order problem that keeps cropping up on the PSP.

The basic problem is this: the GNU linker keeps a list of unresolved symbols. When it comes across a library like -la, it only pulls symbols from -la as necessary in order to satisfy currently unresolved symbols. The good thing about this is that you don't get bloat because of symbols you don't need. But if some later library needs symbols that were in -la, the linker won't (by default) go back and check -la again to find them.

With shared libraries, the library link order doesn't matter (for various reasons) which is why you don't normally come across this under other operating systems.

The second problem is that our PSP libc is a bit strange because it relies on external libraries (-lpspkernel, etc). The general assumption made by the GNU linker is that -lc has no external dependencies. We've chosen to do things this way for the PSP because it makes it easier to streamline binaries by leaving out the parts you don't need. The upshot is that you always need to include other libraries like -lpspkernel after -lc.

What's happening here is this: When linking with psp-g++, GCC automatically appends the libraries -lstdc++ -lm -lc to the end of the linker command line. When you compile with -fexceptions, the C++ library (-lstdc++) uses some symbols from the C library -lc, which uses some symbols from -lpspkernel. But since this is the end of the command line, -lpspkernel is never searched again for those symbols, and you get the errors.

I don't know if there's a good way to fix it within the PSP toolchain, but there are lots of ways you can fix it in your own program:
  1. Add -Wl,--start-group to the front of your g++ commandline. This will cause the linker to keep searching the list of libraries from the beginning until all symbols are resolved. It means link order generally won't matter anymore, but will slow compilation.
  2. Add the -lstdc++ library yourself at the beginning of the library list, so that it shows up before the PSP libraries. The extra -lstdc++ etc at the end of the commandline will then have no effect.
  3. Use some libc functions in your code. For example, if you add a call to "fopen" in your example code, then the necessary stuff is already pulled in from the earlier reference to -lc, and the errors go away.
This is probably showing up in GCC 4.1.0 but not 4.0.2 because of improvements in the exception handler (presumably it uses more libc functions now).
binch
Posts: 28
Joined: Tue Jul 04, 2006 4:17 pm
Location: China

Post by binch »

oh, amazing!
you are a great guy!

thank you!
Post Reply