Compiling C++ Code

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
CyberBill
Posts: 86
Joined: Tue Jul 26, 2005 3:53 pm
Location: Redmond, WA

Compiling C++ Code

Post by CyberBill »

Hi, I'm having some trouble compiling C++ code. I took PSPPets Wifi example, cut out a bunch of the stuff he had in it (Aibo & Clie, Jpeg..). C works just fine and dandy, so I went and renamed all the files to cpp and recompiled. It compiles but I think it fails during linking. Here is (some of) the output:

Code: Select all

Bill@minibox ~/mywifi-cpp
$ make
psp-g++ -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -I. -I/usr/local/p
spdev/psp/sdk/include -O2 -G0 -Wall -fno-exceptions -fno-rtti   -c -o main.o mai
n.cpp
psp-g++ -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -I. -I/usr/local/p
spdev/psp/sdk/include -O2 -G0 -Wall -fno-exceptions -fno-rtti   -c -o pg_redux.o
 pg_redux.cpp

psp-g++ -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -I. -I/usr/local/p
spdev/psp/sdk/include -O2 -G0 -Wall -fno-exceptions -fno-rtti   -c -o nlh.o nlh.
cpp
psp-g++ -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -I. -I/usr/local/p
spdev/psp/sdk/include -O2 -G0 -Wall -fno-exceptions -fno-rtti   -c -o loadutil.o
 loadutil.cpp
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -I. -I/usr/local/p
spdev/psp/sdk/include -O2 -G0 -Wall -c  -o stubs.o stubs.s
stubs.s: Assembler messages:
stubs.s:16: Warning: ignoring changed section attributes for .text.stub
stubs.s:24: Warning: ignoring changed section attributes for .text.stub
stubs.s:55: Warning: ignoring changed section attributes for .text.stub
stubs.s:83: Warning: ignoring changed section attributes for .text.stub
stubs.s:106: Warning: ignoring changed section attributes for .text.stub
stubs.s:116: Warning: ignoring changed section attributes for .text.stub
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall  -L. -L/usr/local/
pspdev/psp/sdk/lib   main.o pg_redux.o nlh.o loadutil.o stubs.o  -lpspdebug -lps
pdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspuser -lpspkernel -o wifitest.elf
main.o: In function `main':
main.cpp:(.text+0x1d8): undefined reference to `sceUtilityCheckNetParam(int)'
main.cpp:(.text+0x1f0): undefined reference to `sceUtilityGetNetParam(int, unsig
ned int, void*)'
main.cpp:(.text+0x200): undefined reference to `sceUtilityGetNetParam(int, unsig
ned int, void*)'
main.cpp:(.text+0x23c): undefined reference to `sceUtilityGetNetParam(int, unsig
ned int, void*)'
main.cpp:(.text+0x25c): undefined reference to `sceUtilityGetNetParam(int, unsig
ned int, void*)'
main.cpp:(.text+0x284): undefined reference to `sceNetApctlConnect(int)'
main.cpp:(.text+0x298): undefined reference to `sceNetApctlGetState(int*)'
main.cpp:(.text+0x2fc): undefined reference to `sceNetApctlGetState(int*)'
main.cpp:(.text+0x360): undefined reference to `sceNetApctlDisconnect()'
main.cpp:(.text+0x424): undefined reference to `sceNetApctlGetInfo(int, void*)'
main.cpp:(.text+0x4b4): undefined reference to `sceNetInetSocket(int, int, int)'

main.cpp:(.text+0x4f0): undefined reference to `sceNetInetBind(int, void*, int)'

main.cpp:(.text+0x504): undefined reference to `sceNetInetListen(int, int)'
main.cpp:(.text+0x520): undefined reference to `sceNetInetAccept(int, void*, int
*)'
main.cpp:(.text+0x540): undefined reference to `sceNetInetSend(int, void const*,
 int, int)'
main.cpp:(.text+0x558): undefined reference to `sceNetInetSend(int, void const*,
 int, int)'
main.cpp:(.text+0x5b8): undefined reference to `sceNetInetRecv(int, unsigned cha
r*, int, int)'
It just continues on after that with the same type of error except for different functions. I know the functions are basically exported in stubs.s but I dont know how that fits into the big picture.

Any help would be appreciated, thanks. :)

-Bill
User avatar
Thanhda
Posts: 331
Joined: Sat Apr 09, 2005 2:08 am
Location: Canada
Contact:

Post by Thanhda »

you should try taking a simple project like "me" and adding c++ code to it. i have manage to implement a class into the project, and compiles just fine, but my only problem is when i try to instantiate a new object in the scene. take a look. also by updating your psptoolchain it will get rid of a lot more of the errors. the package i used was in the samples/me/basic/ folder

http://forums.ps2dev.org/viewtopic.php?t=2803
There are 10 types of people in the world: Those who understand binary, and those who don't...
CyberBill
Posts: 86
Joined: Tue Jul 26, 2005 3:53 pm
Location: Redmond, WA

Post by CyberBill »

I've figured out the problem...

Mixing C/C++ isnt very smart. I needed to add wrappers:

Code: Select all

#ifndef PSPWIFI_H
#define PSPWIFI_H

#ifdef __cplusplus
extern "C" {
#endif

//code goes here


#ifdef __cplusplus
}
#endif

#endif /* PSPWIFI_H */

Now it compies juuuust fine. YEY CLASSES! YEYYY TEMPLATES!!! Wooooottt!!!

I'm going to try and create a socket library with standard berkeley function names... No idea how it would get compiled into a .a though. :-/
Post Reply