c++ code...

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

Moderators: cheriff, TyRaNiD

Post Reply
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

c++ code...

Post by LuMo »

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
Paco
Posts: 54
Joined: Sun Oct 09, 2005 6:53 pm

Post by Paco »

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
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

-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: Select all

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

Code: Select all

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&#58;88&#58; error&#58;  arse error before '<' token
/usr/local/include/audiere.h&#58;93&#58; error&#58;  ptr' undeclared here &#40;not in a function
&#41;
/usr/local/include/audiere.h&#58;94&#58; error&#58; parse error before '&#125;' token
/usr/local/include/audiere.h&#58;96&#58; error&#58; parse error before '<' token
/usr/local/include/audiere.h&#58; In function `RefPtr'&#58;
/usr/local/include/audiere.h&#58;97&#58; error&#58; `m_ptr' undeclared &#40;first use in this fu
nction&#41;
/usr/local/include/audiere.h&#58;97&#58; error&#58; &#40;Each undeclared identifier is reported
only once
/usr/local/include/audiere.h&#58;97&#58; error&#58; for each function it appears in.&#41;
/usr/local/include/audiere.h&#58; At top level&#58;
/usr/local/include/audiere.h&#58;101&#58; error&#58; parse error before '~' token
/usr/local/include/audiere.h&#58;105&#58; error&#58; parse error before '&#125;' token
/usr/local/include/audiere.h&#58;113&#58; error&#58; redefinition of 'm_ptr'
/usr/local/include/audiere.h&#58;104&#58; error&#58; previous definition of 'm_ptr' was here
/usr/local/include/audiere.h&#58;114&#58; error&#58; parse error before "if"
/usr/local/include/audiere.h&#58; In function `bool'&#58;
/usr/local/include/audiere.h&#58;134&#58; error&#58; parse error before '&#123;' token
/usr/local/include/audiere.h&#58; At top level&#58;
/usr/local/include/audiere.h&#58;142&#58; error&#58; parse error before '&#58;' token
/usr/local/include/audiere.h&#58;151&#58; error&#58; parse error before '<' token
/usr/local/include/audiere.h&#58; In function `unref'&#58;
/usr/local/include/audiere.h&#58;170&#58; error&#58; `m_ref_count' undeclared &#40;first use in
this function&#41;
/usr/local/include/audiere.h&#58;171&#58; error&#58; `delete' undeclared &#40;first use in this
function&#41;
/usr/local/include/audiere.h&#58;171&#58; error&#58; parse error before "this"
/usr/local/include/audiere.h&#58; At top level&#58;
/usr/local/include/audiere.h&#58;175&#58; error&#58; parse error before '&#58;' token
/usr/local/include/audiere.h&#58;188&#58; error&#58; parse error before "File"
/usr/local/include/audiere.h&#58;210&#58; error&#58; syntax error before "int"
/usr/local/include/audiere.h&#58;210&#58; error&#58; function `read' is initialized like a v
lumo
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Paco
Posts: 54
Joined: Sun Oct 09, 2005 6:53 pm

Post by Paco »

You have a luasound.c file that contains C++ code, or at least is tring to include C++ header files.
Paco
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

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
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

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.
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

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!)
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
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

Use 'extern "C"' around the lua.h includes and search google or read a good C++ book why you have to do it :-)
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

hehe yeah, i know what you mean,
and thats even what i did...

Code: Select all

extern "C" &#123;
	#include "lua.h"
	#include "lualib.h"
	#include "lauxlib.h"
&#125;
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
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

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.
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

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
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

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 :-)
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

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