C++ ends up in undefined references

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

Moderators: cheriff, TyRaNiD

Post Reply
TokyoDriftPSP
Posts: 17
Joined: Fri Feb 20, 2009 10:33 pm

C++ ends up in undefined references

Post by TokyoDriftPSP »

Hey,
well, I want to use Object Oriented Programming so I took my program (that compiles just great in C), changed it to .cpp, added my classes, added -lstdc++ to the makefile and what happened? I can't compile anymore! It gives me undefined references when linking I think. See the errors:

Code: Select all

1>C:/pspsdk/bin/rm -f mouseconf.elf  framebuffer.o graphics.o sioDriver.o main.o pgeFont.o PARAM.SFO EBOOT.PBP EBOOT.PBP
1>psp-gcc -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -D_PSP_FW_VERSION=150   -c -o framebuffer.o framebuffer.c
1>psp-gcc -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -D_PSP_FW_VERSION=150   -c -o graphics.o graphics.c
1>psp-gcc -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall   -c -o sioDriver.o sioDriver.S
1>psp-g++ -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -fno-exceptions -fno-rtti -D_PSP_FW_VERSION=150   -c -o main.o main.cpp
1>psp-gcc -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -D_PSP_FW_VERSION=150   -c -o pgeFont.o pgeFont.c
1>psp-gcc -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -D_PSP_FW_VERSION=150  -L. -LC:/pspsdk/psp/sdk/lib   framebuffer.o graphics.o sioDriver.o main.o pgeFont.o -lpspgum -lpspgu -lpng -lz -lm -lfreetype -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o mouseconf.elf
1>main.o: In function `get_input_thread(unsigned int, void*)':
1>main.cpp:(.text+0x168): undefined reference to `sioPutchar(int)'
1>main.cpp:(.text+0x18c): undefined reference to `sioReadChar()'
1>main.cpp:(.text+0x1a4): undefined reference to `sioReadChar()'
1>main.cpp:(.text+0x204): undefined reference to `sioReadChar()'
1>main.cpp:(.text+0x214): undefined reference to `sioReadChar()'
1>main.cpp:(.text+0x28c): undefined reference to `resetFBuf()'
1>main.o: In function `initSerialPort()':
1>main.cpp:(.text+0x430): undefined reference to `sioInit(int)'
1>main.o: In function `main':
1>main.cpp:(.text+0x600): undefined reference to `loadImage(char const*)'
1>main.cpp:(.text+0x614): undefined reference to `loadImage(char const*)'
1>main.cpp:(.text+0x628): undefined reference to `loadImage(char const*)'
1>main.cpp:(.text+0x638): undefined reference to `loadImage(char const*)'
1>main.cpp:(.text+0x648): undefined reference to `loadImage(char const*)'
1>main.o:main.cpp:(.text+0x658): more undefined references to `loadImage(char const*)' follow
1>main.o: In function `main':
1>main.cpp:(.text+0x69c): undefined reference to `initGraphics()'
1>main.cpp:(.text+0x6b0): undefined reference to `clearScreen(unsigned int)'
1>main.cpp:(.text+0x6d0): undefined reference to `blitAlphaImageToScreen(int, int, int, int, Image*, int, int)'
1>main.cpp:(.text+0x6d8): undefined reference to `FadeScreen(int)'
1>main.cpp:(.text+0x6f4): undefined reference to `flipScreen()'
1>main.cpp:(.text+0x710): undefined reference to `flipScreen()'
1>main.cpp:(.text+0x784): undefined reference to `clearScreen(unsigned int)'
1>main.cpp:(.text+0x7a8): undefined reference to `blitAlphaImageToScreen(int, int, int, int, Image*, int, int)'
1>main.cpp:(.text+0x808): undefined reference to `blitAlphaImageToScreen(int, int, int, int, Image*, int, int)'
1>main.cpp:(.text+0x810): undefined reference to `guStart()'
1>main.cpp:(.text+0x97c): undefined reference to `blitAlphaImageToScreen(int, int, int, int, Image*, int, int)'
1>main.cpp:(.text+0x98c): undefined reference to `flipScreen()'
1>main.cpp:(.text+0x99c): undefined reference to `FadeScreen(int)'
1>main.cpp:(.text+0x9b0): undefined reference to `flipScreen()'
1>main.cpp:(.text+0x9d8): undefined reference to `blitAlphaImageToScreen(int, int, int, int, Image*, int, int)'
1>main.cpp:(.text+0xa00): undefined reference to `blitAlphaImageToScreen(int, int, int, int, Image*, int, int)'
makefile:

Code: Select all

TARGET = mouseconf
OBJS = framebuffer.o graphics.o sioDriver.o main.o pgeFont.o

CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

LIBS = -lpspgum -lpspgu -lpng -lz -lm -lfreetype


EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Mouse Config

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak

as you can see there are only errors in the stub and the graphics thing, pgeFont doesn't drop any error
pls help
TD
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

All the libraries you are trying to call are written in C.
So normally the externs for those functions in the .h file would be surrounded by

#ifdef __cplusplus
extern "C" {
#endif
...most of the contents of your .h file
#ifdef __cplusplus
}
#endif

It looks like the headers you're using don't do this, so you're getting a compile problem.

Btw, C and C++ are quite different, and you shouldn't necessarily expect your C code to compile as C++.

Jim
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

some c specific options require extern "C" {//code here}

edit: son of a b***h well mine is shorter and says the same thing
TokyoDriftPSP
Posts: 17
Joined: Fri Feb 20, 2009 10:33 pm

Post by TokyoDriftPSP »

well the ifdef __cpluplus extern "C" stuff is in the graphics.h and the pgeFont.h, not in the sioDriver.s - this one is being assembled anyway...
but the errors are there when linking, not before, so i think this can't be caused by a mistake in the sources, can it?
TD
TokyoDriftPSP
Posts: 17
Joined: Fri Feb 20, 2009 10:33 pm

Post by TokyoDriftPSP »

okay i made
extern "C"{
*includes*
*callbacks*
}
in main.cpp and it works now
TD
Post Reply