Page 1 of 1

C++ problem

Posted: Mon Apr 18, 2005 5:14 pm
by apache37
I know this post is not about cracking PSP AES but hopefully it's useful :p

I get a linker issue with this simple c++ file:

#include <stdio.h>
#include <stdlib.h>

class myClass
{
public:
int a;
};

int main()
{
myClass *p = new myClass;

p->a = 5;
printf("Hello Jello...[%d]\n",p->a);

return 0;
}

Here's the make:
$ make
rm -f *.elf *.o
ee-g++ -D_EE -O2 -G0 -Wall -I/usr/local/ps2dev/ps2sdk/ee/include -I/usr/local/ps2dev/ps2sdk/common/include -I. -c stlt
ry.cpp -o stltry.o
ee-gcc -mno-crt0 -T/usr/local/ps2dev/ps2sdk/ee/startup/linkfile -L/usr/local/ps2dev/ps2sdk/ee/lib -Wl,-Ttext -Wl,0xa0000
\
-o stl.elf /usr/local/ps2dev/ps2sdk/ee/startup/crt0.o stltry.o -lpad -lc -lkernel -lc -lsyscall -lkernel
stltry.o(.data+0x11): In function `main':
stltry.cpp: undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
make: *** [stl.elf] Error 1

The makefile uses these:
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal

I'm using the latest toolchain script on cygwin which I just built tonite. If I just use myClass p or myClass *p it works fine. When I make a new one on the heap it shits.


Any ideas ??

Posted: Mon Apr 18, 2005 5:28 pm
by apache37
Please delete this topic. I added EE_CXXFLAGS += -fno-exceptions and it worked.

Sorry bout that :)

Posted: Mon Apr 18, 2005 6:03 pm
by pixel
You could also add -lstdc++ and then support exceptions...

Posted: Mon Apr 18, 2005 6:14 pm
by apache37
pixel wrote:You could also add -lstdc++ and then support exceptions...
Cool thanks.. Am I gonna run into trouble if I want to use <vector> ?

Posted: Mon Apr 18, 2005 7:16 pm
by pixel
No, it should be okay.

Posted: Tue Apr 19, 2005 4:13 am
by apache37
Well here's what I get byt just including <vector> in the same file:
rm -f *.elf *.o
ee-g++ -D_EE -O2 -G0 -Wall -fno-exceptions -I/usr/local/ps2dev/ps2sdk/ee/include
-I/usr/local/ps2dev/ps2sdk/common/include -I. -c stltry.cpp -o stltry.o
In file included from /usr/local/ps2dev/ee/include/c++/3.2.2/cwchar:51,
from /usr/local/ps2dev/ee/include/c++/3.2.2/bits/fpos.h:45,
from /usr/local/ps2dev/ee/include/c++/3.2.2/iosfwd:46,
from /usr/local/ps2dev/ee/include/c++/3.2.2/bits/stl_algobase.h
:70,
from /usr/local/ps2dev/ee/include/c++/3.2.2/vector:67,
from stltry.cpp:3:
/usr/local/ps2dev/ee/include/c++/3.2.2/ctime:71: `difftime' not declared
/usr/local/ps2dev/ee/include/c++/3.2.2/ctime:72: `mktime' not declared
/usr/local/ps2dev/ee/include/c++/3.2.2/ctime:73: `time' not declared
/usr/local/ps2dev/ee/include/c++/3.2.2/ctime:74: `asctime' not declared
/usr/local/ps2dev/ee/include/c++/3.2.2/ctime:75: `ctime' not declared
/usr/local/ps2dev/ee/include/c++/3.2.2/ctime:76: `gmtime' not declared
/usr/local/ps2dev/ee/include/c++/3.2.2/ctime:77: `localtime' not declared
/usr/local/ps2dev/ee/include/c++/3.2.2/ctime:78: `strftime' not declared
make: *** [stltry.o] Error 1

Posted: Tue Apr 19, 2005 4:14 am
by apache37
The quote button shouuld not be so close to the edit :p

Posted: Tue Apr 19, 2005 4:20 am
by pixel
*rollseyes*

Okay, I remember fixing some things for the vector<> template to work... Now, it surely is related to the #include order you do.

Yes, I know, this is not really good. Try #include the various stdio.h and stuff from ps2sdk BEFORE including anything else in your test file.

Posted: Tue Apr 19, 2005 4:31 am
by apache37
Well here are my headers:
#include <stdio.h>
#include <stdlib.h>
#include <vector>

Maybe I need to include some specific headers before vector?

Posted: Tue Apr 19, 2005 6:25 am
by BraveDog
Yes, something changed in the toolchain, becuase I was able to compile Stella at one time. Now I get this.

Code: Select all

In file included from /usr/local/ps2dev/ee/include/c++/3.2.2/cwchar&#58;51,
                 from /usr/local/ps2dev/ee/include/c++/3.2.2/bits/fpos.h&#58;45,
                 from /usr/local/ps2dev/ee/include/c++/3.2.2/iosfwd&#58;46,
                 from /usr/local/ps2dev/ee/include/c++/3.2.2/ios&#58;44,
                 from /usr/local/ps2dev/ee/include/c++/3.2.2/ostream&#58;45,
                 from /usr/local/ps2dev/ee/include/c++/3.2.2/iostream&#58;45,
                 from ../emucore/m6502/src/bspf/src/bspf.hxx&#58;49,
                 from ../emucore/Event.hxx&#58;24,
                 from ../emucore/Booster.cxx&#58;19&#58;
/usr/local/ps2dev/ee/include/c++/3.2.2/ctime&#58;71&#58; `difftime' not declared
/usr/local/ps2dev/ee/include/c++/3.2.2/ctime&#58;72&#58; `mktime' not declared
/usr/local/ps2dev/ee/include/c++/3.2.2/ctime&#58;73&#58; `time' not declared
/usr/local/ps2dev/ee/include/c++/3.2.2/ctime&#58;74&#58; `asctime' not declared
/usr/local/ps2dev/ee/include/c++/3.2.2/ctime&#58;75&#58; `ctime' not declared
/usr/local/ps2dev/ee/include/c++/3.2.2/ctime&#58;76&#58; `gmtime' not declared
/usr/local/ps2dev/ee/include/c++/3.2.2/ctime&#58;77&#58; `localtime' not declared
/usr/local/ps2dev/ee/include/c++/3.2.2/ctime&#58;78&#58; `strftime' not declared
make&#91;2&#93;&#58; *** &#91;Booster.o&#93; Error 1
make&#91;1&#93;&#58; *** &#91;ps2&#93; Error 2
make&#58; *** &#91;default&#93; Error 2

Posted: Tue Apr 19, 2005 7:13 am
by pixel
Okay, I think I know what's wrong. Can you guys try to remove/rename the time.h file in the ee/include directory ?

Posted: Tue Apr 19, 2005 7:21 am
by spambait
I have already ps2sdk patches that solve the cstddef and ctime problems. Maybe somebody code could send me a Personal Message on this board where to mail these.

A more severe problem, though, is that libstdc++ seems to be built against newlib, causing lot's of unresolved symbols.

Maybe the cross toolchain should be revisited, usually you do
1) build cross binutils
2) build a minimal cross-gcc
3) use minimal gcc to build cross libraries ("ps2sdk")
4) build a full gcc, using headers and libs from 3)
5) use full gcc to rebuild cross libraries again [optional step]

Basically this means doing away with newlib, but probably ps2sdk is not complete yet as a substitute. It probably also means moving a lot more symbols into libc so that -lc does not depend on anything but crt* and -lgcc.

Posted: Tue Apr 19, 2005 8:32 am
by pixel
spambait wrote:Basically this means doing away with newlib, but probably ps2sdk is not complete yet as a substitute. It probably also means moving a lot more symbols into libc so that -lc does not depend on anything but crt* and -lgcc.
ps2sdk is really not a complete newlib substitute. Any attempt to fully use the libstdc++ (that is, to use full STL streams and stuff) without newlib will result in a failure anyway.

Now, it is true that one can compile some parts of the libstdc++ using ps2sdk as a substitute. If you have patches to submit, on ps2sdk and/or the toolchain script, feel free to do so, as I said, either here, or on IRC.

Posted: Tue Apr 19, 2005 11:12 am
by BraveDog
Pixel,
I moved $PS2SDK/ee/include/time.h to a junk filename.
Then tried to compile and yes it is moving along with no problems now.

Posted: Tue Apr 19, 2005 5:48 pm
by pixel
Thank you. I'll try to complete time.h so that it complies with the posix standard...