读书人

有木有懂lua与c交互的高分求帮助解决

发布时间: 2012-03-19 22:03:05 作者: rapoo

有木有懂lua与c交互的,高分求帮助
我在网上找的实例,但编译的时候始终报错,大家帮忙看一下

下面是代码:

C/C++ code
#include "lua.h"#include "lualib.h"#include "lauxlib.h"#include <windows.h>//dll中定义抛出函数,原型要是Lua_CFunction/*----------定义函数--------------*/static int MyLuaDLL_HelloWorld(lua_State* L){    MessageBox(NULL,"Hello","World",MB_OK);    return 0;}static int MyLuaDLL_average(lua_State *L){    /* get number of arguments */    int n = lua_gettop(L);    double sum = 0;    int i;    /* loop through each argument */    for (i = 1; i <= n; i++)    {        /* total the arguments */        sum += lua_tonumber(L, i);    }    /* push the average */    lua_pushnumber(L, sum / n);    /* push the sum */    lua_pushnumber(L, sum);    /* return the number of results */    return 2;}/*-----------注册函数---------------*/static const luaL_reg MyLuaDLLFunctions [] ={    {"HelloWorld",MyLuaDLL_HelloWorld},    {"average",MyLuaDLL_average},    {NULL, NULL}};int __cdecl __declspec(dllexport) luaopen_MyLuaDLL(lua_State* L){    luaL_openlib(L, "MyLuaDLL", MyLuaDLLFunctions, 0);    return 1;}


编译的时候报的错:
C/C++ code
Lua_pwdEncrypt.obj : error LNK2001: unresolved external symbol __imp__MessageBoxA@16Lua_pwdEncrypt.obj : error LNK2001: unresolved external symbol "void __cdecl lua_pushnumber(struct lua_State *,double)" (?lua_pushnumber@@YAXPAUlua_State@@N@Z)Lua_pwdEncrypt.obj : error LNK2001: unresolved external symbol "double __cdecl lua_tonumber(struct lua_State *,int)" (?lua_tonumber@@YANPAUlua_State@@H@Z)Lua_pwdEncrypt.obj : error LNK2001: unresolved external symbol "int __cdecl lua_gettop(struct lua_State *)" (?lua_gettop@@YAHPAUlua_State@@@Z)Lua_pwdEncrypt.obj : error LNK2001: unresolved external symbol "void __cdecl luaL_openlib(struct lua_State *,char const *,struct luaL_Reg const *,int)" (?luaL_openlib@@YAXPAUlua_State@@PBDPBUluaL_Reg@@H@Z)Debug/Lua_PwdEncrypt.dll : fatal error LNK1120: 5 unresolved externalsError executing link.exe.


我现在lualib,h等头文件直接拷到工程目录下,添加到工程里了,动态库也拷到工程目录下了,但始终报这个错误,希望大侠们帮帮忙,看看究竟怎么回事啊?

[解决办法]
link 的时候需要 lua 的库
[解决办法]
没有link lua的库的dll,在 lua 里 loadlib 的时候加载不了
[解决办法]
lua ga!。。

读书人网 >C++

热点推荐