创建一个使用C语言编写的供Lua使用的动态链接库:undefined reference to 'luaL_register'。

我正在尝试编译这个C代码以获取一个dll:

#include<windows.h>

#include<lauxlib.h>
#include<lua.h>

/*************/
/* 函数 */
/*************/

/* helloluatex_greetings */
static int helloluatex_greetings(lua_State *L)
{
       printf("Hello to LuaTeX from the world's smallest DLL!");
       return 0;
}

/***************************/
/* Lua名称到C函数 */
/***************************/
static const luaL_Reg helloluatex[] = {{"greetings", helloluatex_greetings},
                                         {NULL, NULL}};

/****************************/
/* 主DLL导出函数 */
/****************************/
LUA_API luaopen_helloluatex (lua_State *L)
{
        luaL_register(L, "helloluatex", helloluatex);
        return 1;
}

但我收到这个错误:

[链接器错误] 对'luaL_register'的引用未定义

我在Windows Vista上使用Dev-C++ 4.9.9.2。

你看到我哪里失败了吗?

点赞
用户726361
用户726361

你需要将 lua51.lib 链接到你的项目中,其中包含了 lua_* 函数的定义。你可以通过进入项目 -> 属性 -> 链接器 -> 输入,将 lua51.lib 添加到库列表中来实现,或者在代码中添加

#pragma comment(lib, "lua51.lib")

来完成。

2012-02-12 21:13:43