| View previous topic :: View next topic |
| Author |
Message |
Lousyphreak
Joined: 25 Jan 2005 Posts: 6
|
Posted: Tue Jan 25, 2005 8:19 pm Post subject: Getting g++ to work |
|
|
ive done some ps2 toolchain installs the past days (1 on linux, 2 on cygwin) but with neither g++ was working...
everything works fine with c, i made testfiles with a plain main(), adding a class, and using new. plain main() works (using ee-g++), but as soon as i add a c++ feature the linker complains about unresolved symbols.
ive even tried replacing ee-gcc with ee-g++ as the linker but neither works. ill give you error messages when i come home, currently the only thing i remember is CreateSema and fioRead and the likes (iirc they are in libkernel, i also has strlen missing which should be also there)
thx in advance
Last edited by Lousyphreak on Thu Jan 27, 2005 5:15 am; edited 1 time in total |
|
| Back to top |
|
 |
pixel
Joined: 30 Jan 2004 Posts: 791
|
Posted: Tue Jan 25, 2005 8:32 pm Post subject: |
|
|
Well, first, use ee-gcc as linker. ee-g++ has its specfiles a bit messed up. Second, you have to tell us exactly what are your errors AND your makefile (that is, we need to exactly know the ee-gcc command you're running in order to do the linking). Otherwise, we will only be able to provide unprecise and unuseful help. _________________ 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 |
|
 |
Lousyphreak
Joined: 25 Jan 2005 Posts: 6
|
Posted: Wed Jan 26, 2005 12:08 am Post subject: |
|
|
i forgot to mention that i'm at work so i dont have access to my dev pc's, but in the meantime i installed ps2dev here@work and voila the exact same errors.
1. i installed the ps2sdk found here: http://ps2dev.org/kb.x?T=1081
2. set paths accordingly
3. cd to ps2dev\ps2lib\ee\samples\hello_c++
4. make (the makefiles are the default makefiles supplied with ps2dev)
resulting ee-gcc/g++ calls (including error):
| Code: | ee-g++ -D_EE -O2 -G0 -Wall -IH:\prog\ps2dev\gcc/ee/include -IH:\prog\ps2dev\gcc/ee/lib/gcc-lib/ee/3.2.2/include -IH:\prog\ps2dev\gcc/ee/ee/include -IH:\prog\ps2dev\ps2lib/ee/include -IH:\prog\ps2dev\ps2lib/common/include -I. -c hello.cpp-o hello.o
ee-gcc -TH:\prog\ps2dev\ps2lib/ee/startup/linkfile -LH:\prog\ps2dev\ps2lib/ee/lib \
hello.o -lkernel -o hello.elf
hello.o(.data+0x11): In function `main':
hello.cpp: undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
make: *** [hello.elf] Error 1 |
if i replace ee-gcc with ee-g++ for the linker (interpreted __gxx_personality_v0 as a hint) and adding -lc to the end it looks more promising:
| Code: | ee-g++ -TH:\prog\ps2dev\ps2lib/ee/startup/linkfile -LH:\prog\ps2dev\ps2lib/ee/lib \
hello.o -lkernel -o hello.elf -lc
/cygdrive/h/prog/ps2dev/gcc/ee/bin/../lib/gcc-lib/ee/3.2.2/../../../../ee/lib/libc.a(sbrk.o)(.text+0x8): In function `sbrk':
../../../../../../newlib/libc/sys/ps2/sbrk.c:8: undefined reference to `ps2_sbrk'
/cygdrive/h/prog/ps2dev/gcc/ee/bin/../lib/gcc-lib/ee/3.2.2/../../../../ee/lib/libc.a(close.o)(.text+0x8): In function `close':
../../../../../../newlib/libc/sys/ps2/close.c:6: undefined reference to `fioClose'
/cygdrive/h/prog/ps2dev/gcc/ee/bin/../lib/gcc-lib/ee/3.2.2/../../../../ee/lib/libc.a(lseek.o)(.text+0x8): In function `lseek':
../../../../../../newlib/libc/sys/ps2/lseek.c:8: undefined reference to `fioLseek'
/cygdrive/h/prog/ps2dev/gcc/ee/bin/../lib/gcc-lib/ee/3.2.2/../../../../ee/lib/libc.a(read.o)(.text+0x8): In function `read':
../../../../../../newlib/libc/sys/ps2/read.c:6: undefined reference to `fioRead'
collect2: ld returned 1 exit status
make: *** [hello.elf] Error 1
|
though i got my 7+ years of c++ programming on my back already im fairly new to the gnu toolchain. thats why i think the 2nd version is the "better" one, but still, i checked libkernel and the missing functions where there (simple grep ;) ) it is also linking to it (removing libkernel.a results in a "-lkernel not found" message) so im a bit at the end of my wisdom.
my first post was actually just a check if there was a known problem with g++ (if even the samples dont work).
hope this helps |
|
| Back to top |
|
 |
boomint
Joined: 13 Apr 2004 Posts: 80 Location: Sheffield, UK
|
Posted: Wed Jan 26, 2005 12:23 am Post subject: |
|
|
You're using an old version that includes ps2lib rather that ps2sdk.
You'd be better off (and probably better supported!) using the toolchain.sh script found in the stable section on ooPo's site :
http://www.oopo.net/consoledev _________________ --( someone stole my sig! )-- |
|
| Back to top |
|
 |
Lousyphreak
Joined: 25 Jan 2005 Posts: 6
|
Posted: Wed Jan 26, 2005 5:22 pm Post subject: |
|
|
now built with toolchain.sh:
| Code: | bash-2.05b$ ee-g++ test.cpp -D_EE -O2 -c
bash-2.05b$ ee-gcc -T/usr/local/ps2dev/ps2sdk/ee/startup/linkfile -L$PS2SDK/ee/lib test.o -lkernel -lstdc++ -lc -lkernel -lsyscall
/usr/local/ps2dev/ee/lib/gcc-lib/ee/3.2.2/libgcc.a(unwind-dw2.o)(.text+0x388): In function `extract_cie_info':
../../gcc/unwind-dw2.c:226: undefined reference to `strlen'
/usr/local/ps2dev/ee/lib/gcc-lib/ee/3.2.2/libgcc.a(unwind-dw2-fde.o)(.text+0x5d4): In function `get_cie_encoding':
../../gcc/unwind-dw2-fde.c:271: undefined reference to `strlen'
collect2: ld returned 1 exit status
|
so i built the ps2sdk in a subdir again and linked strlen.o to the executable, and suddenly it works:
| Code: | | bash-2.05b$ ee-gcc -T/usr/local/ps2dev/ps2sdk/ee/startup/linkfile -L$PS2SDK/ee/lib test.o -lkernel -lstdc++ -lc -lkernel -lsyscall ps2sdk/ee/libc/obj/strlen.o |
so now im curious: why isnt the ps2sdk libc used (i guess i can switch off the newlib libc), ans why is strlen not in libkernel (atleast i think it should be)?
oh btw, test.cpp:
| Code: | class x
{
public:
int muh;
int xy(){};
};
int main()
{
x *y=new x();
return 0;
}
|
i havent tested the resulting elf, for now i'm happy that it builds ;) |
|
| Back to top |
|
 |
BraveDog
Joined: 30 Dec 2004 Posts: 29 Location: Cleveland
|
Posted: Thu Jan 27, 2005 1:40 am Post subject: |
|
|
I have had this problem with libc functions as well. As a work around I added '-lc' in again at the end of libraries to be linked in.
Seemed to get rid of the problem.
-bd |
|
| Back to top |
|
 |
Lousyphreak
Joined: 25 Jan 2005 Posts: 6
|
Posted: Thu Jan 27, 2005 8:59 am Post subject: |
|
|
the -lc workaround doesnt work for me :(
i just search for the compiled .o's which contain the needed function and add them to the linker, currently there are 13 files i need to link to manually. (im toying with scummvm using an old ps2 port and getting it up2date)
for now its working but still it bugs me why i need to link to objs which should already be in the used libs |
|
| Back to top |
|
 |
mharris
Joined: 25 Jan 2004 Posts: 155 Location: Annapolis, MD, USA
|
Posted: Thu Jan 27, 2005 2:08 pm Post subject: |
|
|
| Lousyphreak wrote: | | Code: |
hello.o(.data+0x11): In function `main':
hello.cpp: undefined reference to `__gxx_personality_v0'
|
|
Try adding this to your Makefile
| Code: | | EE_CXXFLAGS += -fno-exceptions |
This disables the extra code g++ adds to support C++ exceptions. Obviously, you won't be able to use exceptions if this flag is turned on (but your code will be smaller and faster...) |
|
| Back to top |
|
 |
rinco
Joined: 21 Jan 2005 Posts: 255 Location: Canberra, Australia
|
Posted: Tue Feb 01, 2005 1:45 am Post subject: |
|
|
I would try overriding the new/delete operators, ie:
| Code: |
void* operator new(size_t size) { return malloc(size); }
void operator delete(void* data) { if (data != 0) free(data); }
/* thanks #ps2dev */
void *operator new[]( size_t n )
{ return ::operator new[](n); }
void operator delete[]( void *p, size_t )
{ ::operator delete[](p); }
void operator delete[]( void *p )
{ ::operator delete[](p); }
/* thanks google */
|
|
|
| Back to top |
|
 |
mrbrown
Joined: 17 Jan 2004 Posts: 1536
|
Posted: Tue Feb 01, 2005 4:21 am Post subject: |
|
|
| Thenend wrote: |
I use these lines to compile and link:
ee-gcc main.cpp -D_EE -O0 -c -Wall -W -EL -G0 -mips3 -nostdlib
|
The -nostdlib line is useless here because you're compling an object module not a program. You generally don't want to use -nostdlib unless you know what you are doing.
Take out the -mips3 line, it's wrong for EE and it's possible it's what's causing your problems.
| Thenend wrote: |
ee-gcc -L$PS2SDK/ee/lib main.o -lkernel -lstdc++ -lc -lkernel -lsyscall strlen.o g2.o dma_asm.o gs_asm.o ps2_asm.o -o main.elf
|
The critical error here is that you don't specify ps2sdk's crt0.o or linkfile. Now I'm 99% certain your program died because it's using newlib's crt0.o, which won't work on PS2.
Refer to the ps2sdk Makefiles or other programs/libraries in CVS for examples of the linker step to use for C++ programs. _________________ "He was warned..." |
|
| Back to top |
|
 |
pixel
Joined: 30 Jan 2004 Posts: 791
|
Posted: Tue Feb 01, 2005 8:20 pm Post subject: |
|
|
| Thenend wrote: | | Yes, I suspected the problem was crt0.o but when I tried to link the ps2sdk one, I get redefinition errors and can't figure out how to take the newlib's crt0.o out of my program :-( |
If you'd tell the errors, maybe we could work that out... _________________ 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 |
|
 |
ooPo Site Admin
Joined: 17 Jan 2004 Posts: 2032 Location: Canada
|
Posted: Tue Feb 01, 2005 11:12 pm Post subject: |
|
|
Sounds like you need to add the linkfile:
-T$PS2SDK/ee/startup/linkfile |
|
| Back to top |
|
 |
Neil Stevens

Joined: 27 Jan 2005 Posts: 79 Location: California
|
Posted: Wed Feb 02, 2005 12:48 am Post subject: |
|
|
If you add crt0.o to your link line, you have to add -mno-crt0 or you'll have a conflict.
Try adding both, while using the linkfile too. |
|
| Back to top |
|
 |
pixel
Joined: 30 Jan 2004 Posts: 791
|
Posted: Wed Feb 02, 2005 1:48 am Post subject: |
|
|
Just a hint: -lsyscall isn't useful anymore. _________________ 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 |
|
 |
mrbrown
Joined: 17 Jan 2004 Posts: 1536
|
Posted: Wed Feb 02, 2005 2:54 am Post subject: |
|
|
And baggy pants went out of style with MC Hammer... _________________ "He was warned..." |
|
| Back to top |
|
 |
ooPo Site Admin
Joined: 17 Jan 2004 Posts: 2032 Location: Canada
|
Posted: Wed Feb 02, 2005 3:59 am Post subject: |
|
|
| Shiny! |
|
| Back to top |
|
 |
OptiRoc
Joined: 02 Feb 2004 Posts: 22 Location: Sweden
|
Posted: Mon Feb 07, 2005 1:10 pm Post subject: |
|
|
I just tried to compile some basic C++ code and ran into the same problem: undefined reference to `strlen'.
Is rolling up and link an own strlen.o the best solution, or is there a cleaner way?
(btw, I just cooked up a fresh ps2dev environment using ooPo's script) |
|
| Back to top |
|
 |
Neil Stevens

Joined: 27 Jan 2005 Posts: 79 Location: California
|
Posted: Mon Feb 07, 2005 10:49 pm Post subject: |
|
|
| Note that the supplied linker is dumb, in the sense that it doesn't do anything smart or tricky. List your libraries so that they all their dependencies to their right, and put the libraries to the right of your object files. |
|
| Back to top |
|
 |
OptiRoc
Joined: 02 Feb 2004 Posts: 22 Location: Sweden
|
Posted: Tue Feb 08, 2005 12:00 am Post subject: |
|
|
OK. Using the makefile included with ps2sdk (Makefile.eeglobal_cpp) the linker command expands to this:
ee-gcc -T/usr/local/ps2dev/ps2sdk/ee/startup/linkfile L/usr/local/ps2dev/ps2sdk/ee/lib -o test.elf test.o -lc -lkernel -lstdc++ -lc -lkernel -lsyscall
Which won't resolve the reference to strlen. I was hoping that "-lc" would sort it out just fine. $PS2SDK/ee/lib/libc.a seem to feature an "strlen" function and it should be included with the above line, shouldn't it? |
|
| Back to top |
|
 |
Neil Stevens

Joined: 27 Jan 2005 Posts: 79 Location: California
|
Posted: Tue Feb 08, 2005 1:25 am Post subject: |
|
|
| Oh, Makefile.eeglobal_cpp never worked for me, either. I just used Makefile.eeglobal and added -lstdc++ to my EE_LIBS. Haven't run into a problem yet. |
|
| Back to top |
|
 |
OptiRoc
Joined: 02 Feb 2004 Posts: 22 Location: Sweden
|
Posted: Tue Feb 08, 2005 12:00 pm Post subject: |
|
|
After some tinkering I can build some C++ code, using both templates, new, etc. Printf() won't work though, with the exact same settings as when building the sample code (except the use of ee-g++ for compiling instead of ee-gcc).
When building the example, gcc throwns a warning:
hello.c:27: warning: implicit declaration of function `printf'
When using gcc I get an error instead:
test.cpp:29: `printf' undeclared (first use this function)
This is how the commands look. Any obvious errors?
ee-g++ -D_EE -O2 -G0 -Wall -I/usr/local/ps2dev/ps2sdk/ee/include -I/usr/local/ps2dev/ps2sdk/common/include -I. -c test.cpp -o test.o
ee-gcc -mno-crt0 -T/usr/local/ps2dev/ps2sdk/ee/startup/linkfile -s -L/usr/local/ps2dev/ps2sdk/ee/lib -o test.elf /usr/local/ps2dev/ps2sdk/ee/startup/crt0.o test.o -lstdc++ -lc -lgcc -lsyscall -lc -lkernel
Are you supposed to link libgcc as well? Can't see it mentioned anywhere here, though it solved the compilation problems for me.. |
|
| Back to top |
|
 |
pixel
Joined: 30 Jan 2004 Posts: 791
|
Posted: Tue Feb 08, 2005 5:25 pm Post subject: |
|
|
The obvious error is you didn't #include <stdio.h> in your test.cpp 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 |
|
 |
OptiRoc
Joined: 02 Feb 2004 Posts: 22 Location: Sweden
|
Posted: Tue Feb 08, 2005 10:04 pm Post subject: |
|
|
Too true. :)
But neither did the example in $PS2SDK/samples/hello! I'm curious how printf() got declared there.
By the way, after some further tinkering I link the following libraries at the end of the linker command: -lkernel -lstdc++ -lc -lgcc -lkernel
I saw your comment that syscalls wasn't used anymore so I cut that one out, together with one "-lc" which seemed necessary after the "-lsyscalls" -- and put another "-lkernel" in front (which was suggested somewhere, I believe..). |
|
| Back to top |
|
 |
Neil Stevens

Joined: 27 Jan 2005 Posts: 79 Location: California
|
Posted: Tue Feb 08, 2005 10:42 pm Post subject: |
|
|
| C is not C++. C lets you get away with junk that C++ disallows. |
|
| Back to top |
|
 |
pixel
Joined: 30 Jan 2004 Posts: 791
|
Posted: Tue Feb 08, 2005 11:24 pm Post subject: |
|
|
The SDK here isn't really stabilized yet. Well, lots of work was done lately which was about cleaning the status of the libc so that it's more "standard" than it was. So, for example, printf's got moved to its right location (stdio) and nobody thought about updating the examples. Same goes with libraries names and dependancies. _________________ 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 |
|
 |
|