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 

c++ code...

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



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Sun Oct 16, 2005 10:08 pm    Post subject: c++ code... Reply with quote

i tried to include a c++ package to my sourcecode today,
and failed, gave me lots of undefined errors (can't show it up, cause i already deleted the files, maybe too fast... *argh*)
before including those files
i did a clean: make and make install, which successfully worked out!
it was even possible to compile the sample projects;

so my question:
is it possible to include c++ code
or is only C99 supported by the sdk/modded compiler

thanks in advance
lumo
_________________
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Back to top
View user's profile Send private message Visit poster's website
Paco



Joined: 09 Oct 2005
Posts: 54

PostPosted: Sun Oct 16, 2005 11:55 pm    Post subject: Reply with quote

I'm using C++ all the way, with STL and the whole shebang.

Try adding -lstdc++ to your LIBS line in the makefile. And of course put the .cpp extension to your C++ source files. .cc and .cxx likely work too but they are ugly. :)
_________________
Paco
Back to top
View user's profile Send private message
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Mon Oct 17, 2005 2:10 am    Post subject: Reply with quote

-lstdc++
is this a standard lib or do i have to svn it somewhere?
(if not standard, where can i get it?)
my c++ code is with .cpp extension :)

thanks for your fast answer

edit:
edited my makefile-flags to:
Code:

LFLAGS = -L/usr/local/lib -lglut32 -lglu32 -llua -llualib -lopengl32 -lpng -lstdc++
CFLAGS = -I$(PSPSDK)/sdk/include -I$(PSPSDK)/include -Isrc


Code:

dc++ -lkernel32
src/luasound.c:9:20: iostream: No such file or directory
src/luasound.c:10:18: memory: No such file or directory
In file included from src/luasound.c:12:
/usr/local/include/audiere.h:21:18: vector: No such file or directory
/usr/local/include/audiere.h:22:18: string: No such file or directory
/usr/local/include/audiere.h:30:4: #error Audiere requires C++
In file included from src/luasound.c:12:
/usr/local/include/audiere.h:61: error: parse error before "audiere"
/usr/local/include/audiere.h:61: error: syntax error before '{' token
/usr/local/include/audiere.h:84: error: syntax error before "void"
/usr/local/include/audiere.h:84: error: function `unref' is initialized like a v
ariable
/usr/local/include/audiere.h:85: error: parse error before '}' token
/usr/local/include/audiere.h:88: error:  arse error before '<' token
/usr/local/include/audiere.h:93: error:  ptr' undeclared here (not in a function
)
/usr/local/include/audiere.h:94: error: parse error before '}' token
/usr/local/include/audiere.h:96: error: parse error before '<' token
/usr/local/include/audiere.h: In function `RefPtr':
/usr/local/include/audiere.h:97: error: `m_ptr' undeclared (first use in this fu
nction)
/usr/local/include/audiere.h:97: error: (Each undeclared identifier is reported
only once
/usr/local/include/audiere.h:97: error: for each function it appears in.)
/usr/local/include/audiere.h: At top level:
/usr/local/include/audiere.h:101: error: parse error before '~' token
/usr/local/include/audiere.h:105: error: parse error before '}' token
/usr/local/include/audiere.h:113: error: redefinition of 'm_ptr'
/usr/local/include/audiere.h:104: error: previous definition of 'm_ptr' was here
/usr/local/include/audiere.h:114: error: parse error before "if"
/usr/local/include/audiere.h: In function `bool':
/usr/local/include/audiere.h:134: error: parse error before '{' token
/usr/local/include/audiere.h: At top level:
/usr/local/include/audiere.h:142: error: parse error before ':' token
/usr/local/include/audiere.h:151: error: parse error before '<' token
/usr/local/include/audiere.h: In function `unref':
/usr/local/include/audiere.h:170: error: `m_ref_count' undeclared (first use in
this function)
/usr/local/include/audiere.h:171: error: `delete' undeclared (first use in this
function)
/usr/local/include/audiere.h:171: error: parse error before "this"
/usr/local/include/audiere.h: At top level:
/usr/local/include/audiere.h:175: error: parse error before ':' token
/usr/local/include/audiere.h:188: error: parse error before "File"
/usr/local/include/audiere.h:210: error: syntax error before "int"
/usr/local/include/audiere.h:210: error: function `read' is initialized like a v


lumo
_________________
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Back to top
View user's profile Send private message Visit poster's website
Paco



Joined: 09 Oct 2005
Posts: 54

PostPosted: Mon Oct 17, 2005 2:40 am    Post subject: Reply with quote

You have a luasound.c file that contains C++ code, or at least is tring to include C++ header files.
_________________
Paco
Back to top
View user's profile Send private message
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Mon Oct 17, 2005 2:47 am    Post subject: Reply with quote

thats my aim... include a cpp header file...
--> changed the file to luasound.cpp
get some new errors now (which were working just fine before)
but i will fix that for sure :)

EDIT:
is there a way to include cpp to c without changing the c code to cpp?
would be hard work to change all the already done work to cpp

thanks for your help :)
_________________
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Back to top
View user's profile Send private message Visit poster's website
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Mon Oct 17, 2005 6:09 am    Post subject: Reply with quote

LuMo wrote:
is there a way to include cpp to c without changing the c code to cpp?
would be hard work to change all the already done work to cpp


The other way works: If you have some C code, you can include the functions and variables with 'extern "C"' in a C++ file from a header file. Using C++ from C functions is possible, too, but more difficult (wrapper functions etc. are needed, if you are using classes and objects, like iostream).

But luasound.c looks like you are trying to use C++ in Lua Player. I've thought myself about converting it to C++, because the syntax is a bit easier (no need for "struct" in variable definitions, for (int i=.. etc.) and it catches some more errors at compile time. Perhaps you should ask this in the Lua Player forum, to hear some opinions.
Back to top
View user's profile Send private message
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Mon Oct 17, 2005 11:19 pm    Post subject: Reply with quote

well, i adapted the filenames, and changed the includes, modified some code to get rid of errors;
worked fine to to a point...
since i am only coding in c/cpp for some weeks now i do not understand why i get the following errors (screens full!)

Quote:

cygwin/Temp/cccDt85J.o:luagraphics.cpp:(.text+0x1a3
): undefined reference to `lua_remove(lua_State*, int)'
cygwin/Temp/cccDt85J.o:luagraphics.cpp:(.text+0x1a6e
): undefined reference to `lua_remove(lua_State*, int)'
cygwin/Temp/cccDt85J.o:luagraphics.cpp:(.text+0x1a83
): undefined reference to `luaL_error(lua_State*, char const*, ...)'
cygwin/Temp/cccDt85J.o:luagraphics.cpp:(.text+0x1a9e
): undefined reference to `luaL_checkint(lua_State*, int)'
cygwin/Temp/cccDt85J.o:luagraphics.cpp:(.text+0x1ab
): undefined reference to `luaL_checkint(lua_State*, int)'
cygwin/Temp/cccDt85J.o:luagraphics.cpp:(.text+0x1b0
): undefined reference to `luaL_checkint(lua_State*, int)'
cygwin/Temp/cccDt85J.o:luagraphics.cpp:(.text+0x1b2f
): undefined reference to `luaL_checkint(lua_State*, int)'
cygwin/Temp/cccDt85J.o:luagraphics.cpp:(.text+0x1b5
): undefined reference to `luaL_checkint(lua_State*, int)'
cygwin/Temp/cccDt85J.o:luagraphics.cpp:(.text+0x1b8
): more undefined references to `luaL_checkint(lua_State*, int)' follow
cygwin/Temp/cccDt85J.o:luagraphics.cpp:(.text+0x1ca3
): undefined reference to `lua_gettop(lua_State*)'
cygwin/Temp/cccDt85J.o:luagraphics.cpp:(.text+0x1cd1
): undefined reference to `luaL_error(lua_State*, char const*, ...)'
cygwin/Temp/cccDt85J.o:luagraphics.cpp:(.text+0x1cf
): undefined reference to `lua_toboolean(lua_State*, int)'
cygwin/Temp/cccDt85J.o:luagraphics.cpp:(.text+0x1d2
): undefined reference to `lua_settop(lua_State*, int)'
cygwin/Temp/cccDt85J.o:luagraphics.cpp:(.text+0x1d4

so, actually i know what undefined reference means; BUT why do i get that? was working in c just fine (and nowhere in the code are those functions defined) so i guess its an include from the lua library? (please do not tell me that i have to convert that to cpp...)

thanks in advance
lumo
_________________
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Back to top
View user's profile Send private message Visit poster's website
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Tue Oct 18, 2005 1:51 am    Post subject: Reply with quote

Use 'extern "C"' around the lua.h includes and search google or read a good C++ book why you have to do it :-)
Back to top
View user's profile Send private message
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Tue Oct 18, 2005 2:09 am    Post subject: Reply with quote

hehe yeah, i know what you mean,
and thats even what i did...
Code:
extern "C" {
   #include "lua.h"
   #include "lualib.h"
   #include "lauxlib.h"
}


i even included ALL psp-related includes to extern "C" afterwards
but, heh, still getting those errors...
_________________
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Back to top
View user's profile Send private message Visit poster's website
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Tue Oct 18, 2005 2:16 am    Post subject: Reply with quote

Can you publish your current project? Perhaps it's easier when I see where all the includes are and how the new Makefiles looks like.
Back to top
View user's profile Send private message
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Tue Oct 18, 2005 2:30 am    Post subject: Reply with quote

sure, the only thing i am trying, is to put luaplayer to c++
EDIT:
bugga i forgot the makefile
greets
lumo
PS: the link is in the text :)
_________________
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Back to top
View user's profile Send private message Visit poster's website
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Tue Oct 18, 2005 8:00 am    Post subject: Reply with quote

I can't reproduce your bugs, but when removing the lumo_graphics.cpp from the Makefile, which was not in your package, I get some errors for undefined sce-functions. The reason is that in emulator.cpp for example pspdisplay.h was not imported. This means, some functions are defined with C++ linkage, so it can't be found when included with extern "C". After including all headers, it compiles to an exe. Sometimes C++ is tricky :-)
Back to top
View user's profile Send private message
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Tue Oct 18, 2005 7:47 pm    Post subject: Reply with quote

well i am now at the point where only the sce functions are missing;
i have no clue which headerfile to include...
only those files do not seem to find the sce-functions:
    luaysystem.cpp
    graphic.cpp

(more might pop up when those are solved ;) )

maybe you could upload my modded files?

EDIT:
eg.: graphic.cpp cannot find "sceGuShadeModel"
although i tried both
#include <pspgu.h>
and
extern "C" {
#include <pspgu.h>
}
still says that this function is not available (but it is!)

TIA
lumo
_________________
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.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