using c and c++ code in one project = compile error ???

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

Moderators: cheriff, TyRaNiD

Post Reply
lastyle
Posts: 6
Joined: Wed Feb 01, 2006 3:39 am

using c and c++ code in one project = compile error ???

Post by lastyle »

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
PeterM
Posts: 125
Joined: Sat Dec 31, 2005 7:25 pm
Location: Edinburgh, UK
Contact:

Post by PeterM »

What errors do you get? (copy and paste please)
lastyle
Posts: 6
Joined: Wed Feb 01, 2006 3:39 am

here we go

Post by lastyle »

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++.
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Post by sg57 »

seems to me that ur header file is either wrong, or you made a typo on your functions and such, amke sure you ahve ur header named right

#ifdef JEG_H
#endif JEG_H

or something like that
cheriff
Regular
Posts: 258
Joined: Wed Jun 23, 2004 5:35 pm
Location: Sydney.au

Re: here we go

Post by cheriff »

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
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.
You might wanna double check your makefile?
Damn, I need a decent signature!
lastyle
Posts: 6
Joined: Wed Feb 01, 2006 3:39 am

Post by lastyle »

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
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

The compilers work, and I've done this before - you must still have a path wrong somewhere. Or a missing object.

Jim
lastyle
Posts: 6
Joined: Wed Feb 01, 2006 3:39 am

Post by lastyle »

Maybe its a bug in the latest SDK then ? i updated mine with the latest toolchain.

Probably i need to mention that i am using cygwin, if that may help finding the problem.

But could anybody please verify using the elf_sample and JGE kit, to make me 101% sure its not my setup please.

Thanks,Mario
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

It's not the toolchain. You can't just add JGE.cpp to the project, you need to add all the other cpp source files too!

Jim
lastyle
Posts: 6
Joined: Wed Feb 01, 2006 3:39 am

Post by lastyle »

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
PeterM
Posts: 125
Joined: Sat Dec 31, 2005 7:25 pm
Location: Edinburgh, UK
Contact:

Post by PeterM »

I mix C and C++ in my Quake port, and that's with a pretty recent SDK - about a week old.

I really think the problem is with your makefile.

Pete
lastyle
Posts: 6
Joined: Wed Feb 01, 2006 3:39 am

Post by lastyle »

Hi Pete,
i posted my makefile above, is there any real difference to yours ?

Mario
charliex
Posts: 16
Joined: Thu Jan 26, 2006 4:03 pm

Post by charliex »

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.
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

<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
Post Reply