我正在尝试编译此 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/