Getting g++ to work
-
- Posts: 6
- Joined: Tue Jan 25, 2005 5:28 pm
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
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.
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.
-
- Posts: 6
- Joined: Tue Jan 25, 2005 5:28 pm
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):
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:
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
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: Select all
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: Select all
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
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
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! )--
-
- Posts: 6
- Joined: Tue Jan 25, 2005 5:28 pm
now built with toolchain.sh:
so i built the ps2sdk in a subdir again and linked strlen.o to the executable, and suddenly it works:
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:
i havent tested the resulting elf, for now i'm happy that it builds ;)
Code: Select all
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
Code: Select all
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
oh btw, test.cpp:
Code: Select all
class x
{
public:
int muh;
int xy(){};
};
int main()
{
x *y=new x();
return 0;
}
-
- Posts: 6
- Joined: Tue Jan 25, 2005 5:28 pm
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
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
Try adding this to your MakefileLousyphreak wrote:Code: Select all
hello.o(.data+0x11): In function `main': hello.cpp: undefined reference to `__gxx_personality_v0'
Code: Select all
EE_CXXFLAGS += -fno-exceptions
I would try overriding the new/delete operators, ie:
Code: Select all
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 */
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.Thenend wrote: I use these lines to compile and link:
ee-gcc main.cpp -D_EE -O0 -c -Wall -W -EL -G0 -mips3 -nostdlib
Take out the -mips3 line, it's wrong for EE and it's possible it's what's causing your problems.
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.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
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..."
If you'd tell the errors, maybe we could work that out...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 :-(
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.
- Neil Stevens
- Posts: 79
- Joined: Thu Jan 27, 2005 2:22 pm
- Location: California
- Contact:
- Neil Stevens
- Posts: 79
- Joined: Thu Jan 27, 2005 2:22 pm
- Location: California
- Contact:
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?
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?
- Neil Stevens
- Posts: 79
- Joined: Thu Jan 27, 2005 2:22 pm
- Location: California
- Contact:
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..
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..
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.
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..).
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..).
- Neil Stevens
- Posts: 79
- Joined: Thu Jan 27, 2005 2:22 pm
- Location: California
- Contact: