【发布时间】:2018-04-04 06:54:59
【问题描述】:
我正在尝试使用以下方法从 lua 文件创建可执行文件:
我使用 bintocee 实用程序(来自:http://lua-users.org/wiki/BinToCee)将 myfile.lua 转换为 code.c 。然后我使用以下 main.c(来自:Creating standalone Lua executables)
#include <stdlib.h>
#include <stdio.h>
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
int main(int argc, char *argv[]) {
int i;
lua_State *L = luaL_newstate();
luaL_openlibs(L);
lua_newtable(L);
for (i = 0; i < argc; i++) {
lua_pushnumber(L, i);
lua_pushstring(L, argv[i]);
lua_rawset(L, -3);
}
lua_setglobal(L, "arg");
#include "code.c"
lua_close(L);
return 0;
}
然后我发出命令:
gcc main.c -o myfile.exe
但是,我收到以下错误:
/tmp/ccyIOC0O.o: In function `main':
main.c:(.text+0x21): undefined reference to `luaL_newstate'
main.c:(.text+0x2f): undefined reference to `luaL_openlibs'
main.c:(.text+0x41): undefined reference to `lua_createtable'
main.c:(.text+0x62): undefined reference to `lua_pushnumber'
main.c:(.text+0x82): undefined reference to `lua_pushstring'
main.c:(.text+0x92): undefined reference to `lua_rawset'
main.c:(.text+0xb7): undefined reference to `lua_setfield'
main.c:(.text+0xd5): undefined reference to `luaL_loadbuffer'
main.c:(.text+0xea): undefined reference to `lua_pcall'
main.c:(.text+0xf8): undefined reference to `lua_close'
collect2: error: ld returned 1 exit status
我正在开发 Linux Debian Stable(已更新)。问题出在哪里,如何解决?感谢您的帮助。
【问题讨论】:
-
对
lua有一点想法,但它显然需要链接一些库。 -
我尝试安装 liblua5.1 和 liblua5.1-dev 但同样的错误仍然存在。
-
你需要链接。
gcc main.c -llua -o myfile.exe之类的东西(不知道实际名称)