使用 C : undefined reference to 'luaL_register' 为 Lua 创建一个 dll

标签 c lua

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

#include<windows.h>

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

/*************/
/* FUNCTIONS */
/*************/

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

/***************************/
/* Lua name to C functions */
/***************************/
static const luaL_Reg helloluatex[] = {{"greetings", helloluatex_greetings},
                                         {NULL, NULL}};

/****************************/
/* MAIN DLL EXPORT FUNCTION */
/****************************/
LUA_API luaopen_helloluatex (lua_State *L)
{
        luaL_register(L, "helloluatex", helloluatex);
        return 1;
}

但是我收到这个错误:

[linker error] undefined reference to 'luaL_register'

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

你看到我失败的地方了吗?

最佳答案

您必须将 lua51.lib 链接到您的项目中,其中包含 lua_* 函数的定义。您可以通过转到 Project -> Properties -> Linker -> Input 并将 lua51.lib 添加到库列表,或通过添加

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

代码中的某处。

关于使用 C : undefined reference to 'luaL_register' 为 Lua 创建一个 dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9252064/

相关文章:

object - Lua 在元表中设置 __index

c - 为什么这个sin cos在弧度很大的时候查表不准确?

c - 使用另一个函数查找最大数字

c++ - 将 Lua 绑定(bind)胶水代​​码与我的游戏引擎的其余部分隔离开来

从C调用Lua函数: Minimal example results in LUA_ERRRUN

路亚: Dynamically calling a function with arguments

c - ODBC 单连接或每线程一个连接

c - 关于命名管道的简短阅读(matlab->linux)

c - 图 C 实现 - 深度优先搜索

lua - 尝试索引全局 'event'(零值)