C++ problem

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
apache37
Posts: 76
Joined: Fri Jun 04, 2004 3:13 pm

C++ problem

Post 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 ??
apache37
Posts: 76
Joined: Fri Jun 04, 2004 3:13 pm

Post by apache37 »

Please delete this topic. I added EE_CXXFLAGS += -fno-exceptions and it worked.

Sorry bout that :)
pixel
Posts: 791
Joined: Fri Jan 30, 2004 11:43 pm

Post by pixel »

You could also add -lstdc++ and then support exceptions...
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
apache37
Posts: 76
Joined: Fri Jun 04, 2004 3:13 pm

Post 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> ?
pixel
Posts: 791
Joined: Fri Jan 30, 2004 11:43 pm

Post by pixel »

No, it should be okay.
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
apache37
Posts: 76
Joined: Fri Jun 04, 2004 3:13 pm

Post 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
Last edited by apache37 on Tue Apr 19, 2005 4:14 am, edited 1 time in total.
apache37
Posts: 76
Joined: Fri Jun 04, 2004 3:13 pm

Post by apache37 »

The quote button shouuld not be so close to the edit :p
pixel
Posts: 791
Joined: Fri Jan 30, 2004 11:43 pm

Post 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.
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
apache37
Posts: 76
Joined: Fri Jun 04, 2004 3:13 pm

Post 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?
BraveDog
Posts: 29
Joined: Thu Dec 30, 2004 1:16 am
Location: Cleveland

Post 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
pixel
Posts: 791
Joined: Fri Jan 30, 2004 11:43 pm

Post 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 ?
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
spambait
Posts: 6
Joined: Sun Apr 17, 2005 8:59 pm

Post 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.
pixel
Posts: 791
Joined: Fri Jan 30, 2004 11:43 pm

Post 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.
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
BraveDog
Posts: 29
Joined: Thu Dec 30, 2004 1:16 am
Location: Cleveland

Post 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.
pixel
Posts: 791
Joined: Fri Jan 30, 2004 11:43 pm

Post by pixel »

Thank you. I'll try to complete time.h so that it complies with the posix standard...
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
Post Reply