my code
inline int DOFILE(string& filename) {
printf("lua_open\n");
/* initialize Lua */
lua_State* L = lua_open();
printf("lua_openlibs\n");
/* load Lua base libraries */
luaL_openlibs(L);
printf("lua_dofile\n");
/* run the script */
int ret = luaL_dofile(L, filename.c_str());
printf("lua_close\n");
/* cleanup Lua */
lua_close(L);
return ret;
}
compile options:
obj.cxxflags = ["-g", "-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE", "-Wall", "-llua-5.1"]
also tried ‘-llua’, ‘-llualib’, all of them report warning
i686-apple-darwin11-llvm-g++-4.2: -llua-5.1: linker input file unused because linking not done
When I run, it report:
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
You should be using the
obj.ldflagsparameter for libraries.The build tool you are using produces its binaries in two steps:
The compile step uses the
obj.cxxflagscompiler flags. Libraries are not needed to compile, so passing linker flags (-lfoo) in there is no useful – the compiler doesn’t use them at all (hence the warnings).The link step should use both
obj.cxxflagsandobj.ldflags. (ldis the name of the linker.)(It is not uncommon for very simple code to do both compiling and linking at the same time, e.g. with
g++ -o thing thing.cpp -lpthread. But for larger builds, separating compiling and linking is usual.)