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

embed lua runtime error: Symbol not found: _luaL_newstate

本文关键字:luaL newstate lua 运行时错误 符号 嵌入      更新时间:2023-10-16

我的代码

inline int DOFILE(string& filename) {
  printf("lua_openn");
  /* initialize Lua */
  lua_State* L = lua_open();
  printf("lua_openlibsn");
  /* load Lua base libraries */
  luaL_openlibs(L);
  printf("lua_dofilen");
  /* run the script */
  int ret = luaL_dofile(L, filename.c_str());
  printf("lua_closen");
  /* cleanup 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

您应该为库使用obj.ldflags参数。

您正在使用的构建工具分两步生成二进制文件:

  1. 链接

编译步骤使用obj.cxxflags编译器标志。库不需要编译,所以传递链接器标志(-lfoo)是没有用的——编译器根本不使用它们(因此有警告)。

链接步骤应同时使用obj.cxxflagsobj.ldflags。(ld是链接器的名称)

非常简单的代码同时进行编译和链接并不罕见,例如g++ -o thing thing.cpp -lpthread。但是对于较大的构建,通常将编译和链接分开。)
相关文章:
  • 没有找到相关文章