using c and c++ code in one project = compile error ???
using c and c++ code in one project = compile error ???
Hi Boys, i am trying to use JGE`s libs that were included within the StarBugz release.
First of all, i have no problems compiling any SDK sample nor the c++ StarBugz or Demo sourcecodes included.
As SDK sample i used the elf_template for testing purposes which also compiled fine, but as soon as i include "Demo.h" and ofcourse modified the makefile with "OBJS = main.o Demo.o ../JGE/JGE.o" it doesnt work anymore.
Is there a special setting i have to use in the makefile to get this working ?
Greets, Mario
First of all, i have no problems compiling any SDK sample nor the c++ StarBugz or Demo sourcecodes included.
As SDK sample i used the elf_template for testing purposes which also compiled fine, but as soon as i include "Demo.h" and ofcourse modified the makefile with "OBJS = main.o Demo.o ../JGE/JGE.o" it doesnt work anymore.
Is there a special setting i have to use in the makefile to get this working ?
Greets, Mario
here we go
Here we go
lA-sTYLe@l3000-894757b92 ~/test
$ make
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -L. -L/usr/local
/pspdev/psp/sdk/lib main.o Demo.o -lpng -lz -lm -lmikmod -lmmio -lpspaudiolib
-lpspaudio -lpspgu -lstdc++ -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk
-lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspus
er -lpspkernel -o JGEDemo.elf
Demo.o: In function `Demo::Demo()':
Demo.cpp:(.text+0xc): undefined reference to `JGE::JGE()'
Demo.o: In function `Demo::Demo()':
Demo.cpp:(.text+0x48): undefined reference to `JGE::JGE()'
Demo.o: In function `Demo::~Demo()':
Demo.cpp:(.text+0x80): undefined reference to `JGE::~JGE()'
Demo.o: In function `Demo::~Demo()':
Demo.cpp:(.text+0x90): undefined reference to `JGE::~JGE()'
Demo.o: In function `Demo::~Demo()':
Demo.cpp:(.text+0xb0): undefined reference to `JGE::~JGE()'
Demo.o: In function `Demo::Create()':
Demo.cpp:(.text+0xec): undefined reference to `JGE_Gfx::Gfx_LoadTexture(char con
st*, bool)'
Demo.cpp:(.text+0x120): undefined reference to `JQuad::JQuad(JTexture*, float, f
loat, float, float)'
Demo.cpp:(.text+0x13c): undefined reference to `JQuad::SetHotSpot(float, float)'
Demo.cpp:(.text+0x170): undefined reference to `JQuad::JQuad(JTexture*, float, f
loat, float, float)'
Demo.cpp:(.text+0x18c): undefined reference to `JQuad::SetHotSpot(float, float)'
Demo.o: In function `Demo::Destroy()':
Demo.cpp:(.text+0x1e4): undefined reference to `JGE_Gfx::Gfx_FreeTexture(JTextur
e*)'
Demo.o: In function `Demo::Render()':
Demo.cpp:(.text+0x260): undefined reference to `JGE_Gfx::Gfx_FillRect(int, int,
int, int, unsigned short)'
Demo.cpp:(.text+0x27c): undefined reference to `JGE_Gfx::Gfx_RenderQuad(JQuad*,
float, float)'
Demo.cpp:(.text+0x2ac): undefined reference to `JGE_Gfx::Gfx_RenderQuad(JQuad*,
float, float, float, float, float)'
Demo.cpp:(.text+0x2d0): undefined reference to `JGE_Gfx::Gfx_RenderQuad(JQuad*,
float, float, float, float, float)'
Demo.cpp:(.text+0x2dc): undefined reference to `JQuad::SetColor(unsigned short)'
Demo.cpp:(.text+0x304): undefined reference to `JGE_Gfx::Gfx_RenderQuad(JQuad*,
float, float, float, float, float)'
Demo.cpp:(.text+0x310): undefined reference to `JQuad::SetColor(unsigned short)'
Demo.cpp:(.text+0x350): undefined reference to `JGE_Gfx::Gfx_RenderQuad(JQuad*,
float, float, float, float, float)'
Demo.o: In function `Demo::Update()':
Demo.cpp:(.text+0x384): undefined reference to `JGE::Timer_GetDelta()'
Demo.cpp:(.text+0x444): undefined reference to `JGE::End()'
Demo.cpp:(.text+0x4c4): undefined reference to `JGE_Gfx::Gfx_ScreenShot(char con
st*)'
collect2: ld returned 1 exit status
make: *** [JGEDemo.elf] Error 1
lA-sTYLe@l3000-894757b92 ~/test
$[/img]
_____
So compiler tries to compile c code instead of c++ , as my main.c is ansi-c
compiler doesnt notice the other codes beeing c++.
lA-sTYLe@l3000-894757b92 ~/test
$ make
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -L. -L/usr/local
/pspdev/psp/sdk/lib main.o Demo.o -lpng -lz -lm -lmikmod -lmmio -lpspaudiolib
-lpspaudio -lpspgu -lstdc++ -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk
-lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspus
er -lpspkernel -o JGEDemo.elf
Demo.o: In function `Demo::Demo()':
Demo.cpp:(.text+0xc): undefined reference to `JGE::JGE()'
Demo.o: In function `Demo::Demo()':
Demo.cpp:(.text+0x48): undefined reference to `JGE::JGE()'
Demo.o: In function `Demo::~Demo()':
Demo.cpp:(.text+0x80): undefined reference to `JGE::~JGE()'
Demo.o: In function `Demo::~Demo()':
Demo.cpp:(.text+0x90): undefined reference to `JGE::~JGE()'
Demo.o: In function `Demo::~Demo()':
Demo.cpp:(.text+0xb0): undefined reference to `JGE::~JGE()'
Demo.o: In function `Demo::Create()':
Demo.cpp:(.text+0xec): undefined reference to `JGE_Gfx::Gfx_LoadTexture(char con
st*, bool)'
Demo.cpp:(.text+0x120): undefined reference to `JQuad::JQuad(JTexture*, float, f
loat, float, float)'
Demo.cpp:(.text+0x13c): undefined reference to `JQuad::SetHotSpot(float, float)'
Demo.cpp:(.text+0x170): undefined reference to `JQuad::JQuad(JTexture*, float, f
loat, float, float)'
Demo.cpp:(.text+0x18c): undefined reference to `JQuad::SetHotSpot(float, float)'
Demo.o: In function `Demo::Destroy()':
Demo.cpp:(.text+0x1e4): undefined reference to `JGE_Gfx::Gfx_FreeTexture(JTextur
e*)'
Demo.o: In function `Demo::Render()':
Demo.cpp:(.text+0x260): undefined reference to `JGE_Gfx::Gfx_FillRect(int, int,
int, int, unsigned short)'
Demo.cpp:(.text+0x27c): undefined reference to `JGE_Gfx::Gfx_RenderQuad(JQuad*,
float, float)'
Demo.cpp:(.text+0x2ac): undefined reference to `JGE_Gfx::Gfx_RenderQuad(JQuad*,
float, float, float, float, float)'
Demo.cpp:(.text+0x2d0): undefined reference to `JGE_Gfx::Gfx_RenderQuad(JQuad*,
float, float, float, float, float)'
Demo.cpp:(.text+0x2dc): undefined reference to `JQuad::SetColor(unsigned short)'
Demo.cpp:(.text+0x304): undefined reference to `JGE_Gfx::Gfx_RenderQuad(JQuad*,
float, float, float, float, float)'
Demo.cpp:(.text+0x310): undefined reference to `JQuad::SetColor(unsigned short)'
Demo.cpp:(.text+0x350): undefined reference to `JGE_Gfx::Gfx_RenderQuad(JQuad*,
float, float, float, float, float)'
Demo.o: In function `Demo::Update()':
Demo.cpp:(.text+0x384): undefined reference to `JGE::Timer_GetDelta()'
Demo.cpp:(.text+0x444): undefined reference to `JGE::End()'
Demo.cpp:(.text+0x4c4): undefined reference to `JGE_Gfx::Gfx_ScreenShot(char con
st*)'
collect2: ld returned 1 exit status
make: *** [JGEDemo.elf] Error 1
lA-sTYLe@l3000-894757b92 ~/test
$[/img]
_____
So compiler tries to compile c code instead of c++ , as my main.c is ansi-c
compiler doesnt notice the other codes beeing c++.
Re: here we go
errr, i'm assuming that all the jge stuff is compiled into this ../JGE/JGE.o of which you speak. looking at the command being run, is isnt being linked in, only main.o and Demo.o are.lastyle wrote:psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -L. -L/usr/local/pspdev/psp/sdk/lib main.o Demo.o -lpng -lz -lm -lmikmod -lmmio -lpspaudiolib -lpspaudio -lpspgu -lstdc++ -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o JGEDemo.elf
You might wanna double check your makefile?
Damn, I need a decent signature!
Yes, your are right with your suggestion. Path iss ../JGE/JGE.o, and the makefile looks like this:
TARGET = alsample
OBJS = main.o texture.o Demo.o ../JGE/JGE.o
INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
LIBS = -lpng -lz -lm -lmikmod -lmmio -lpspaudiolib -lpspaudio -lpspgu -lstdc++
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = I dont care 0.1
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
texture.o: texture.raw
bin2o -i texture.raw texture.o texture
So everything is right. like i posted above, its 100% sure that my code is Ansi-c and the JGE engine is C++, and the SDKCompiler doesnt recnorize that the JGE code is C++ . So as there are some differences within c and c++ some values, ints and floats would have to be changed. I could change my code to c++ layout or convert JGE`s code to c but as this isnt really wanted from my side, i was thinking of some SDK switches that may specify if the code to compile is either c or c++.
Besides that , If i would compile c++ as main (first file) and add a ansi-c code, with an include the compiler crashes with nearly the same errors , as it wants to compile the c source with the c++ compiling methods.
I hope adding the switches this is possible anyhow as i think i am not the only one who is running into that kind of problems, maybe not yet but probably in the next future.
Mario
TARGET = alsample
OBJS = main.o texture.o Demo.o ../JGE/JGE.o
INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
LIBS = -lpng -lz -lm -lmikmod -lmmio -lpspaudiolib -lpspaudio -lpspgu -lstdc++
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = I dont care 0.1
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
texture.o: texture.raw
bin2o -i texture.raw texture.o texture
So everything is right. like i posted above, its 100% sure that my code is Ansi-c and the JGE engine is C++, and the SDKCompiler doesnt recnorize that the JGE code is C++ . So as there are some differences within c and c++ some values, ints and floats would have to be changed. I could change my code to c++ layout or convert JGE`s code to c but as this isnt really wanted from my side, i was thinking of some SDK switches that may specify if the code to compile is either c or c++.
Besides that , If i would compile c++ as main (first file) and add a ansi-c code, with an include the compiler crashes with nearly the same errors , as it wants to compile the c source with the c++ compiling methods.
I hope adding the switches this is possible anyhow as i think i am not the only one who is running into that kind of problems, maybe not yet but probably in the next future.
Mario
If You had a look at the JGEDemo (main.cpp)
______
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include "Demo.h"
_______________
i also set the includes. And James himself told me that there is a prob mixing c and c++. Thats why i was asking for somebody with an older SDK build to backcheck the Problem.
Mario
______
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include "Demo.h"
_______________
i also set the includes. And James himself told me that there is a prob mixing c and c++. Thats why i was asking for somebody with an older SDK build to backcheck the Problem.
Mario
there are only a few things it can be
correct .o file not being included in the link step either by not including it on an all in one compile/link step or in the ld
answer: check the makefile , final link stage
C being compiled wth C compiler and attempting to link to cpp (though it shouldnt compile)
answer: compile with the C++ compiler
C being compiled with C++ compiler and using extern "C" to drop any name mangling
answer: don't use extern "C" for anything other than calling C functions compiled in a C file from C++
dump the .o file and see if it contains the functions you think it should
but it looks to me like either its not being linked in or the calling convetion/name space isnt the same for both files.
you should be able to compile C files as C++ with only minor fixes if any.
correct .o file not being included in the link step either by not including it on an all in one compile/link step or in the ld
answer: check the makefile , final link stage
C being compiled wth C compiler and attempting to link to cpp (though it shouldnt compile)
answer: compile with the C++ compiler
C being compiled with C++ compiler and using extern "C" to drop any name mangling
answer: don't use extern "C" for anything other than calling C functions compiled in a C file from C++
dump the .o file and see if it contains the functions you think it should
but it looks to me like either its not being linked in or the calling convetion/name space isnt the same for both files.
you should be able to compile C files as C++ with only minor fixes if any.
<snip rubbish>
I see now that JGE.cpp #includes all the other source files. Doh.
<later>
I found the starbugz v001 source, went into the Demo directory and typed 'make'. That didn't quite work and I had to remove the -G0 option in the Makefile. After that it cleaned and built fine with today's PSPSDK.
But if I understand right, you've taken the elf_template from the SDK and just added Demo.h? I tried that with main.c from elf_template and of course it doesn't work (can't build because Demo.h is C++ and main.c is C). So I renamed main.c to main.cpp and that built perfectly.
If this isn't what you've done, can you post your main.c/main.cpp?
Jim
I see now that JGE.cpp #includes all the other source files. Doh.
<later>
I found the starbugz v001 source, went into the Demo directory and typed 'make'. That didn't quite work and I had to remove the -G0 option in the Makefile. After that it cleaned and built fine with today's PSPSDK.
But if I understand right, you've taken the elf_template from the SDK and just added Demo.h? I tried that with main.c from elf_template and of course it doesn't work (can't build because Demo.h is C++ and main.c is C). So I renamed main.c to main.cpp and that built perfectly.
If this isn't what you've done, can you post your main.c/main.cpp?
Jim