1

I am trying to build LuaJava on OSX Snow Leopard and I am getting a linking problem. I have modified the config script for OSX and I have ensured that all of the paths there are correct. I had to change luajava.c(line 2795) to have lua_resume take two LuaStates. This gets it past the building stage but it fails on linking. This is what I get:

export MACOSX_DEPLOYMENT_TARGET=10.6; gcc -dynamiclib -all_load -o libluajava-1.1.jnilib src/c/luajava.o /usr/local/lib/liblua.a
Undefined symbols for architecture x86_64:
  "_luaL_findtable", referenced from:
      _Java_org_keplerproject_luajava_LuaState__1LfindTable in luajava.o
  "_luaL_setn", referenced from:
      _Java_org_keplerproject_luajava_LuaState__1LsetN in luajava.o
  "_luaL_getn", referenced from:
      _Java_org_keplerproject_luajava_LuaState__1LgetN in luajava.o
  "_luaL_typerror", referenced from:
      _Java_org_keplerproject_luajava_LuaState__1Ltyperror in luajava.o
  "_lua_getgccount", referenced from:
      _Java_org_keplerproject_luajava_LuaState__1getGcCount in luajava.o
  "_lua_setfenv", referenced from:
      _Java_org_keplerproject_luajava_LuaState__1setFEnv in luajava.o
  "_lua_getfenv", referenced from:
      _Java_org_keplerproject_luajava_LuaState__1getFEnv in luajava.o
  "_lua_objlen", referenced from:
      _Java_org_keplerproject_luajava_LuaState__1objlen in luajava.o
  "_lua_strlen", referenced from:
      _Java_org_keplerproject_luajava_LuaState__1strlen in luajava.o
  "_lua_lessthan", referenced from:
      _Java_org_keplerproject_luajava_LuaState__1lessthan in luajava.o
  "_lua_equal", referenced from:
      _Java_org_keplerproject_luajava_LuaState__1equal in luajava.o
  "_lua_open", referenced from:
      _Java_org_keplerproject_luajava_LuaState__1open in luajava.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [libluajava-1.1.jnilib] Error 1

Which I don't understand since I just built lua from soruce for this system. Any ideas?

CaseyB
  • 24,780
  • 14
  • 77
  • 112
  • `ld: symbol(s) not found for architecture x86_64` - are you sure you built Lua as a 64-bit library? – Michal Kottman Mar 06 '12 at 23:16
  • How did you compile Lua? Using the standard `make macosx`? Because I did that, modified `config` in LuaJava to point to my `liblua.a` and it compiled correctly... – Michal Kottman Mar 07 '12 at 18:50
  • Yeah, that's exactly what I did! – CaseyB Mar 07 '12 at 18:58
  • I looked at your post below. Could it be that I tried building it against Lua 5.2? – CaseyB Mar 07 '12 at 20:30
  • Yup, it's because I was trying to build against Lua 5.2. Your post below worked perfectly! – CaseyB Mar 07 '12 at 20:36
  • 1
    I should have noticed that the references were only to functions which were changed/removed in Lua 5.2 - `lua_strlen` and `lua_objlen` were merged to `lua_rawlen`, `luaL_typerror` was removed etc. – Michal Kottman Mar 08 '12 at 09:03

1 Answers1

2

I am not sure what is wrong with your setup, here what I did to compile LuaJava successfully on Mac OS X Lion:

Download & compile latest Lua 5.1

$ wget http://www.lua.org/ftp/lua-5.1.5.tar.gz
$ tar xzf lua-5.1.5.tar.gz
$ cd lua-5.1.5
$ make -j macosx
$ make install
$ cd ..

Download LuaJava

$ wget https://github.com/jasonsantos/luajava/zipball/master
$ mv master luajava.zip
$ unzip luajava.zip
$ mv jasonsantos-luajava-32a3fcd/ luajava
$ cd luajava

Edit the config file

$ diff -u config.old config
--- config.old  2007-12-27 08:38:30.000000000 +0100
+++ config  2012-03-07 20:11:28.000000000 +0100
@@ -1,11 +1,11 @@
 #############################################################
 #Linux/BSD/Mac
-LUA_DIR= /usr/local/share/lua/5.1.1
+LUA_DIR= /usr/local/share/lua/5.1
 LUA_LIBDIR= /usr/local/lib
-LUA_INCLUDES= /usr/local/include
-JDK= $(JAVA_HOME)
+LUA_INCLUDES= -I/usr/local/include -I/System/Library/Frameworks/JavaVM.framework/Headers
+#JDK= $(JAVA_HOME)
 # For Mac OS, comment the above line and uncomment this one
-#JDK=/Library/Java/Home
+JDK=/Library/Java/Home

 # Full path to Lua static library
 LIB_LUA=$(LUA_LIBDIR)/liblua.a
@@ -18,15 +18,15 @@
 LIB_PREFIX= lib

 #Linux/BSD
-LIB_OPTION= -shared
+#LIB_OPTION= -shared
 #Mac OS
-#LIB_OPTION= -dynamiclib -all_load
+LIB_OPTION= -dynamiclib -all_load

 ## On FreeBSD and Mac OS systems, the following line should be commented
 DLLIB= -ldl

 WARN= -O2 -Wall -fPIC -W -Waggregate-return -Wcast-align -Wmissing-prototypes -Wnested-externs -Wshadow -Wwrite-strings
-INCS= -I$(JDK)/include -I$(JDK)/include/linux -I$(LUA_INCLUDES)
+INCS= -I$(JDK)/include -I$(JDK)/include/linux $(LUA_INCLUDES)
 CFLAGS= $(WARN) $(INCS)

 CC= gcc

Compile LuaJava

$ make
gcc -O2 -Wall -fPIC -W -Waggregate-return -Wcast-align -Wmissing-prototypes -Wnested-externs -Wshadow -Wwrite-strings -I/Library/Java/Home/include -I/Library/Java/Home/include/linux -I/usr/local/include -I/System/Library/Frameworks/JavaVM.framework/Headers   -c -o src/c/luajava.o src/c/luajava.c
... a million warnings later ...
export MACOSX_DEPLOYMENT_TARGET=10.3; gcc -dynamiclib -all_load -o libluajava-1.1.so src/c/luajava.o /usr/local/lib/liblua.a
------------------
Build Complete
------------------
Michal Kottman
  • 16,375
  • 3
  • 47
  • 62