QuickCocos C++绑定Lua后编译出错

我在quick\lib\extra 增加了一个测试类:
*
*
//cpp
*#include “MyExt.h”

int MyExt::Adder(int a, int b)
{
return a + b;
}

//header
#ifndef MY_EXT_H
#define MY_EXT_H

class MyExt
{
public:
static int Adder(int a, int b);
};

#endif

然后在cocos2dx_extra_luabinding.tolua
加了头文件和pkg代码
$#include “myExt/MyExt.h”

class MyExt
{
static int Adder(int a, int b);
};

build.bat编译也通过了,但是在重编Player3的时候出错了……

2>libquick.lib(cocos2dx_extra_luabinding.obj) : error LNK2019: unresolved external symbol “public: static void __cdecl cocos2d::extra::Native::showActivityIndicator(void)” (?showActivityIndicator@Native@extra@cocos2d@@SAXXZ) referenced in function “int __cdecl tolua_cocos2dx_extra_luabinding_Native_showActivityIndicator00(struct lua_State *)” (?tolua_cocos2dx_extra_luabinding_Native_showActivityIndicator00@@YAHPAUlua_State@@@Z)
2>libquick.lib(cocos2dx_extra_luabinding.obj) : error LNK2019: unresolved external symbol “public: static void __cdecl cocos2d::extra::Native::hideActivityIndicator(void)” (?hideActivityIndicator@Native@extra@cocos2d@@SAXXZ) referenced in function “int __cdecl tolua_cocos2dx_extra_luabinding_Native_hideActivityIndicator00(struct lua_State *)” (?tolua_cocos2dx_extra_luabinding_Native_hideActivityIndicator00@@YAHPAUlua_State@@@Z)
2>libquick.lib(cocos2dx_extra_luabinding.obj) : error LNK2019: unresolved external symbol “public: static void __cdecl cocos2d::extra::Native::createAlert(char const *,char const *,char const *)” (?createAlert@Native@extra@cocos2d@@SAXPBD00@Z) referenced in function “int __cdecl tolua_cocos2dx_extra_luabinding_Native_createAlert00(struct lua_State *)” (?tolua_cocos2dx_extra_luabinding_Native_createAlert00@@YAHPAUlua_State@@@Z)
2>libquick.lib(cocos2dx_extra_luabinding.obj) : error LNK2019: unresolved external symbol “public: static int __cdecl cocos2d::extra::Native::addAlertButton(char const *)” (?addAlertButton@Native@extra@cocos2d@@SAHPBD@Z) referenced in function “int __cdecl tolua_cocos2dx_extra_luabinding_Native_addAlertButton00(struct lua_State *)” (?tolua_cocos2dx_extra_luabinding_Native_addAlertButton00@@YAHPAUlua_State@@@Z)
2>libquick.lib(cocos2dx_extra_luabinding.obj) : error LNK2019: unresolved external symbol “public: static void __cdecl cocos2d::extra::Native::cancelAlert(void)” (?cancelAlert@Native@extra@cocos2d@@SAXXZ) referenced in function “int __cdecl tolua_cocos2dx_extra_luabinding_Native_cancelAlert00(struct lua_State *)” (?tolua_cocos2dx_extra_luabinding_Native_cancelAlert00@@YAHPAUlua_State@@@Z)
2>libquick.lib(cocos2dx_extra_luabinding.obj) : error LNK2019: unresolved external symbol “public: static class std::basic_string<char,struct std::char_traits,class std::allocator > const __cdecl cocos2d::extra::Native::getOpenUDID(void)” (?getOpenUDID@Native@extra@cocos2d@@SA?BV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function “int __cdecl tolua_cocos2dx_extra_luabinding_Native_getOpenUDID00(struct lua_State *)” (?tolua_cocos2dx_extra_luabinding_Native_getOpenUDID00@@YAHPAUlua_State@@@Z)
2>libquick.lib(cocos2dx_extra_luabinding.obj) : error LNK2019: unresolved external symbol “public: static void __cdecl cocos2d::extra::Native::openURL(char const *)” (?openURL@Native@extra@cocos2d@@SAXPBD@Z) referenced in function “int __cdecl tolua_cocos2dx_extra_luabinding_Native_openURL00(struct lua_State *)” (?tolua_cocos2dx_extra_luabinding_Native_openURL00@@YAHPAUlua_State@@@Z)
2>libquick.lib(cocos2dx_extra_luabinding.obj) : error LNK2019: unresolved external symbol “public: static class std::basic_string<char,struct std::char_traits,class std::allocator > const __cdecl cocos2d::extra::Native::getInputText(char const *,char const *,char const *)” (?getInputText@Native@extra@cocos2d@@SA?BV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PBD00@Z) referenced in function “int __cdecl tolua_cocos2dx_extra_luabinding_Native_getInputText00(struct lua_State *)” (?tolua_cocos2dx_extra_luabinding_Native_getInputText00@@YAHPAUlua_State@@@Z)
2>libquick.lib(cocos2dx_extra_luabinding.obj) : error LNK2019: unresolved external symbol “public: static class std::basic_string<char,struct std::char_traits,class std::allocator > const __cdecl cocos2d::extra::Native::getDeviceName(void)” (?getDeviceName@Native@extra@cocos2d@@SA?BV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function “int __cdecl tolua_cocos2dx_extra_luabinding_Native_getDeviceName00(struct lua_State *)” (?tolua_cocos2dx_extra_luabinding_Native_getDeviceName00@@YAHPAUlua_State@@@Z)
2>libquick.lib(cocos2dx_extra_luabinding.obj) : error LNK2019: unresolved external symbol “public: static void __cdecl cocos2d::extra::Native::vibrate(void)” (?vibrate@Native@extra@cocos2d@@SAXXZ) referenced in function “int __cdecl tolua_cocos2dx_extra_luabinding_Native_vibrate00(struct lua_State *)” (?tolua_cocos2dx_extra_luabinding_Native_vibrate00@@YAHPAUlua_State@@@Z)
2>libquick.lib(cocos2dx_extra_luabinding.obj) : error LNK2019: unresolved external symbol “public: static void __cdecl cocos2d::extra::Native::showAlertLua(int)” (?showAlertLua@Native@extra@cocos2d@@SAXH@Z) referenced in function “int __cdecl tolua_cocos2dx_extra_luabinding_Native_showAlert00(struct lua_State *)” (?tolua_cocos2dx_extra_luabinding_Native_showAlert00@@YAHPAUlua_State@@@Z)

是不是重编
**cocos2dx_extra_luabinding.tolua的时候把原来的某些代码抹掉了呢?
**求助应该如何解决。

第一个问题已经解决,果然是build.bat的时候,把几个宏给抹掉了,我用对比工具把那几个宏merge过去就能编译过了。现在问题来了,学挖掘机……不对

问题是,我把framework_precompile.zip重新编了一遍,但是没有在里面发现我的,MyExt包。
如何在脚本里使用我的MyExt,默认extra里的东西会被加载到那个包里面?需要加载哪个包么?

绑定好脚本里就可以直接用了

我试了一下,直接写
local reault = MyExt.Adder( 1,2 )

会报错提示 MyExt是nil。

和Quick3.2的文件结构有关系吗,是否需要把某些库重新设置一下?

生成的绑定文件加到工程里了没有?

我是直接加到cocos2dx_extra_luabinding.tolua里面然后用build.bat生成。

生成的是cocos2dx_extra_luabinding.cpp,默认就是在工程里面的。

参考网上的教程做,说是加到那个文件就可以。

绑定代码是指这些么?

//cocos2dx_extra_luabinding.cpp

/* method: Adder of class MyExt /
#ifndef TOLUA_DISABLE_tolua_cocos2dx_extra_luabinding_MyExt_Adder00
static int tolua_cocos2dx_extra_luabinding_MyExt_Adder00(lua_State
tolua_S)
{
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
if (
!tolua_isusertable(tolua_S,1,“MyExt”,0,&tolua_err) ||
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
!tolua_isnumber(tolua_S,3,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,4,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
int a = ((int) tolua_tonumber(tolua_S,2,0));
int b = ((int) tolua_tonumber(tolua_S,3,0));
{
int tolua_ret = (int) MyExt::Adder(a,b);
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function ‘Adder’.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE

/* Open function /
TOLUA_API int tolua_cocos2dx_extra_luabinding_open (lua_State
tolua_S)
{
tolua_open(tolua_S);
tolua_reg_types(tolua_S);
tolua_module(tolua_S,“cc”,0);
tolua_beginmodule(tolua_S,“cc”);

tolua_cclass(tolua_S, “MyExt”, “MyExt”, “”, NULL);
tolua_beginmodule(tolua_S, “MyExt”);
tolua_function(tolua_S, “Adder”, tolua_cocos2dx_extra_luabinding_MyExt_Adder00);
tolua_endmodule(tolua_S);

tolua_cclass(tolua_S,“Crypto”,“Crypto”,"",NULL);
tolua_beginmodule(tolua_S,“Crypto”);
tolua_function(tolua_S,“getAES256KeyLength”,tolua_cocos2dx_extra_luabinding_Crypto_getAES256KeyLength00);
tolua_function(tolua_S,“encryptAES256”,tolua_cocos2dx_extra_luabinding_Crypto_encryptAES25600);

这代码里绑定的是cc.MyExt

谢谢大神。

没找到的原因有两个,一个是你说的使用cc.MyExt访问,还有一个问题就是我的IDE默认去 player/ProjWin32/bin/里面找Player3和对应DLL。我把Debug里面的所有文件拷贝到Bin文件夹下面,然后按照cc.MyExt的方式访问,终于能使用了。

楼主可以写一个简明教程么,现在就没有一个靠谱的,感觉现在你至少是弄好了

:8:
我也也是按照网上的教程弄的,
http://blog.csdn.net/w00w12l/article/details/40430379
最后不能访问,报nil错误,找来好久问题,原来前面要加 cc.,终于可以用了

噢 苍天啊!感谢大神