【发布时间】:2012-07-31 14:32:15
【问题描述】:
我试图在 C++ 中嵌入 lua 代码,但遇到了一个奇怪的编译器错误。这是我的代码:
#include <stdio.h>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
}
int main() {
lua_State *luaVM = luaL_newstate();
if (luaVM == NULL) {
printf("Error initializing lua!\n");
return -1;
}
luaL_openlibs(luaVM);
luaL_dofile(luaVM, "test.lua");
lua_close(luaVM);
return 0;
}
编译:
g++ -Wall -o embed -llua embed.cpp
错误是:
g++ -Wall -o embed -llua embed.cpp
/tmp/ccMGuzal.o: In function `main':
embed.cpp:(.text+0x47): undefined reference to `luaL_loadfilex'
embed.cpp:(.text+0x72): undefined reference to `lua_pcallk'
collect2: error: ld returned 1 exit status
我没有从我的代码中调用luaL_loadfilex 或lua_pcallk,这有助于假设问题不在我的代码中,而在 lua 本身。有人在这里有什么想法吗?
更新
这是我的版本信息:
$ lua -v
Lua 5.2.0 Copyright (C) 1994-2011 Lua.org, PUC-Rio
【问题讨论】:
-
@MartinSchröder 请注意,这也是我的问题。我决定,在找出导致该问题的原因(lualib 不存在)后,最好将其作为一个新问题提出,并继续编辑该问题。
-
啊。抱歉,我没注意到。