brettlangdon / NodeLua

Lua Bindings For Node.JS
85 stars 21 forks source link

Trying to use #11

Open benanders opened 10 years ago

benanders commented 10 years ago

Hi

I'm trying to use NodeLua for a simple project, but I can't seem to run the examples after much trouble trying to install it.

Trying to run the files example code, I get:

dyld: lazy symbol binding failed: Symbol not found: _luaL_newstate
  Referenced from: /Users/benanderson/Desktop/test/node_modules/nodelua/build/Release/nodelua.node
  Expected in: dynamic lookup

dyld: Symbol not found: _luaL_newstate
  Referenced from: /Users/benanderson/Desktop/test/node_modules/nodelua/build/Release/nodelua.node
  Expected in: dynamic lookup

Probably meaning it can't find the Lua headers (which are in /usr/include/lua5.1). Is there a way I can point node to the location of these headers? Putting the headers in /usr/include, /usr/include/include, or /usr/local/include still results in the same error message.

I've installed it using (which seems to be the only way that will work):

MacBook-Pro-2:test user$ export NODELUA_INCLUDE="/usr/include/lua5.1"
MacBook-Pro-2:test user$ export NODELUA_FLAGS="-llua5.1"
MacBook-Pro-2:test user$ sudo npm install git://github.com/brettlangdon/NodeLua

I'm trying to run the example code with sudo node index.js

I'd really like to use this library - I need Lua 5.1 for the project. I'm using OSX 10.9, Lua 5.1.5.

brettlangdon commented 10 years ago

hmm, it probably would have given the error "cannot find lua.h" if it couldn't find the headers.

how did you install the lua headers? are you sure you have the lua5.1 headers and not lua 5.2? 5.2 uses a slightly different C API.

when you install it that way, it does compile and install? If so, then yes, the feature of adding the env variables is only in git right now, I have not published a release version with those yet. I was waiting on someone to test.

benanders commented 10 years ago

Thanks for a prompt reply. It is definitely Lua 5.1, these definitions are at the top of the lua.h file:

#define LUA_VERSION "Lua 5.1"
#define LUA_RELEASE "Lua 5.1.5"
#define LUA_VERSION_NUM 501
#define LUA_COPYRIGHT   "Copyright (C) 1994-2012 Lua.org, PUC-Rio"
#define LUA_AUTHORS     "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"

I installed Lua by downloading the Lua 5.1 source, cding into the directory, and running make macosx, then make install, which installed the headers to /usr/local/include, but I copied them into /usr/include/lua5.1. Changing NODELUA_INCLUDE to point to /usr/local/include runs the same way as using /usr/include/lua5.1.

Installing NodeLua the way I mentioned in the opening post is the only way that worked for me. Running without the sudo breaks, as does plain npm install nodelua. I get the same error presented in this comment https://github.com/brettlangdon/NodeLua/issues/10#issuecomment-31623112 if I try and install it without using the lastest version on git and setting the NODELUA_INCLUDE and NODELUA_FLAGS.

brettlangdon commented 10 years ago

hey @GravityScore I just published the changes which include the environment variables to npm, so now doing:

NODELUA_INCLUDE="/usr/include/lua5.1" NODELUA_FLAGS="-llua5.1" npm install nodelua

Should work. I am not sure why you need sudo, there is probably a permissions issue somewhere. Either in the directory you are doing install from, or if you are trying to install globally or something.

SheldonPacotti commented 10 years ago

This might be too crude of a hack, but after much effort under OSX, including using dlopen() to open the lua library, I couldn't get Node to load the needed symbols at runtime, so I just statically linked to the Lua library when building the NodeLua package (added the final line "liblua.a"):

 "libraries": [
    "<!(echo $NODELUA_FLAGS)",
    "<!(pkg-config --libs-only-l --silence-errors lua || pkg-config --libs-only-l --silence-errors lua5.2 || echo '')",
    "-ldl",
    "liblua.a"
]

Still working through some issues, but this got me past the symbol-loading problem.