forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

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

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
lastyle



Joined: 01 Feb 2006
Posts: 6

PostPosted: Fri Feb 03, 2006 7:30 am    Post subject: using c and c++ code in one project = compile error ??? Reply with quote

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
Back to top
View user's profile Send private message
PeterM



Joined: 31 Dec 2005
Posts: 125
Location: Edinburgh, UK

PostPosted: Fri Feb 03, 2006 10:11 am    Post subject: Reply with quote

What errors do you get? (copy and paste please)
Back to top
View user's profile Send private message Visit poster's website
lastyle



Joined: 01 Feb 2006
Posts: 6

PostPosted: Fri Feb 03, 2006 4:20 pm    Post subject: here we go Reply with quote

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++.
Back to top
View user's profile Send private message
sg57



Joined: 14 Oct 2005
Posts: 154

PostPosted: Fri Feb 03, 2006 5:24 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
cheriff
Regular


Joined: 23 Jun 2004
Posts: 262
Location: Sydney.au

PostPosted: Fri Feb 03, 2006 5:40 pm    Post subject: Re: here we go Reply with quote

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!
Back to top
View user's profile Send private message
lastyle



Joined: 01 Feb 2006
Posts: 6

PostPosted: Sat Feb 04, 2006 1:47 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Sat Feb 04, 2006 8:56 am    Post subject: Reply with quote

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

Jim
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
lastyle



Joined: 01 Feb 2006
Posts: 6

PostPosted: Sat Feb 04, 2006 9:22 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Sat Feb 04, 2006 2:28 pm    Post subject: Reply with quote

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
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
lastyle



Joined: 01 Feb 2006
Posts: 6

PostPosted: Sat Feb 04, 2006 7:36 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
PeterM



Joined: 31 Dec 2005
Posts: 125
Location: Edinburgh, UK

PostPosted: Sat Feb 04, 2006 8:21 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
lastyle



Joined: 01 Feb 2006
Posts: 6

PostPosted: Sat Feb 04, 2006 8:43 pm    Post subject: Reply with quote

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

Mario
Back to top
View user's profile Send private message
charliex



Joined: 26 Jan 2006
Posts: 16

PostPosted: Sun Feb 05, 2006 7:04 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Sun Feb 05, 2006 7:31 am    Post subject: Reply with quote

<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
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group