嵌入式lua运行时错误:未找到符号:_luaL_newstate

我的代码

inline int DOFILE(string& filename) {

  printf("lua_open\n");
  /* 初始化 Lua */
  lua_State* L = lua_open();

  printf("lua_openlibs\n");
  /* 加载 Lua 基本库 */
  luaL_openlibs(L);

  printf("lua_dofile\n");
  /* 运行脚本 */
  int ret = luaL_dofile(L, filename.c_str());

  printf("lua_close\n");
  /* 清理 Lua */
  lua_close(L);

  return ret;
}

编译选项:

obj.cxxflags = ["-g", "-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE", "-Wall", "-llua-5.1"]

也尝试了 '-llua' 和 '-llualib',所有的都报告了警告:

i686-apple-darwin11-llvm-g++-4.2: -llua-5.1: linker input file unused because linking not done

当我运行时,它报告:

lua_open
dyld: lazy symbol binding failed: Symbol not found: _luaL_newstate
  Referenced from: /Users/gl/workspace/node-lua/build/Release/node_lua.node
  Expected in: flat namespace

dyld: Symbol not found: _luaL_newstate
  Referenced from: /Users/gl/workspace/node-lua/build/Release/node_lua.node
  Expected in: flat namespace

原文链接 https://stackoverflow.com/questions/8552955

点赞
stackoverflow用户635608
stackoverflow用户635608

你应该使用 obj.ldflags 参数来添加库。

你正在使用的构建工具将其二进制文件生成为两个步骤:

  1. 编译
  2. 链接

编译步骤使用 obj.cxxflags 编译器标志。在编译时不需要库文件,因此在此处传递链接器标志(如 -lfoo)没有用处 - 编译器根本不使用它们(因此会出现警告)。

链接步骤应该同时使用 obj.cxxflagsobj.ldflagsld 是链接器的名称)。

(在非常简单的代码中,同时进行编译和链接是很常见的,例如 g++ -o thing thing.cpp -lpthread。但对于较大的代码,将编译和链接分开是通常的做法。)

2011-12-18 16:22:51