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++ problem

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



Joined: 04 Jun 2004
Posts: 76

PostPosted: Mon Apr 18, 2005 5:14 pm    Post subject: C++ problem Reply with quote

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 ??
Back to top
View user's profile Send private message
apache37



Joined: 04 Jun 2004
Posts: 76

PostPosted: Mon Apr 18, 2005 5:28 pm    Post subject: Reply with quote

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

Sorry bout that :)
Back to top
View user's profile Send private message
pixel



Joined: 30 Jan 2004
Posts: 791

PostPosted: Mon Apr 18, 2005 6:03 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
apache37



Joined: 04 Jun 2004
Posts: 76

PostPosted: Mon Apr 18, 2005 6:14 pm    Post subject: Reply with quote

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> ?
Back to top
View user's profile Send private message
pixel



Joined: 30 Jan 2004
Posts: 791

PostPosted: Mon Apr 18, 2005 7:16 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
apache37



Joined: 04 Jun 2004
Posts: 76

PostPosted: Tue Apr 19, 2005 4:13 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
apache37



Joined: 04 Jun 2004
Posts: 76

PostPosted: Tue Apr 19, 2005 4:14 am    Post subject: Reply with quote

The quote button shouuld not be so close to the edit :p
Back to top
View user's profile Send private message
pixel



Joined: 30 Jan 2004
Posts: 791

PostPosted: Tue Apr 19, 2005 4:20 am    Post subject: Reply with quote

*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.
Back to top
View user's profile Send private message
apache37



Joined: 04 Jun 2004
Posts: 76

PostPosted: Tue Apr 19, 2005 4:31 am    Post subject: Reply with quote

Well here are my headers:
#include <stdio.h>
#include <stdlib.h>
#include <vector>

Maybe I need to include some specific headers before vector?
Back to top
View user's profile Send private message
BraveDog



Joined: 30 Dec 2004
Posts: 29
Location: Cleveland

PostPosted: Tue Apr 19, 2005 6:25 am    Post subject: Reply with quote

Yes, something changed in the toolchain, becuase I was able to compile Stella at one time. Now I get this.

Code:

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/ios:44,
                 from /usr/local/ps2dev/ee/include/c++/3.2.2/ostream:45,
                 from /usr/local/ps2dev/ee/include/c++/3.2.2/iostream:45,
                 from ../emucore/m6502/src/bspf/src/bspf.hxx:49,
                 from ../emucore/Event.hxx:24,
                 from ../emucore/Booster.cxx:19:
/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[2]: *** [Booster.o] Error 1
make[1]: *** [ps2] Error 2
make: *** [default] Error 2
Back to top
View user's profile Send private message
pixel



Joined: 30 Jan 2004
Posts: 791

PostPosted: Tue Apr 19, 2005 7:13 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
spambait



Joined: 17 Apr 2005
Posts: 6

PostPosted: Tue Apr 19, 2005 7:21 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
pixel



Joined: 30 Jan 2004
Posts: 791

PostPosted: Tue Apr 19, 2005 8:32 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
BraveDog



Joined: 30 Dec 2004
Posts: 29
Location: Cleveland

PostPosted: Tue Apr 19, 2005 11:12 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
pixel



Joined: 30 Jan 2004
Posts: 791

PostPosted: Tue Apr 19, 2005 5:48 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 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