1

This problem has stucked me for days. I have very few knowledge on C, recently I downloaded "jnlua-0.9.6-src.zip" from "https://code.google.com/p/jnlua/downloads/list" and try to compile jnlua.c with following command:

mingw32-gcc -m32 -O2 -c -o jnlua.o jnlua.c -Id:\luarock\lua -Id:\java\include\win32 -Id:\java\include

As a result, the compiler prints several screens of error messages, below are some of them:

jnlua.c:120:1: error: unknown type name 'JNLUA_THREADLOCAL'
 JNLUA_THREADLOCAL JNIEnv *thread_env;
 ^
jnlua.c:120:26: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
 JNLUA_THREADLOCAL JNIEnv *thread_env;
                          ^
jnlua.c:138:1: error: unknown type name 'JNLUA_THREADLOCAL'
 JNLUA_THREADLOCAL jobject newstate_obj;
 ^
jnlua.c:138:27: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'newstate_obj'
 JNLUA_THREADLOCAL jobject newstate_obj;
                           ^
jnlua.c: In function 'newstate_protected':
jnlua.c:148:11: error: 'thread_env' undeclared (first use in this function)
  *ref = (*thread_env)->NewWeakGlobalRef(thread_env, newstate_obj);
           ^
jnlua.c:148:11: note: each undeclared identifier is reported only once for each function it appears in
jnlua.c:148:53: error: 'newstate_obj' undeclared (first use in this function)
  *ref = (*thread_env)->NewWeakGlobalRef(thread_env, newstate_obj);
                                                     ^
jnlua.c: In function 'Java_com_naef_jnlua_LuaState_lua_1newstate':
jnlua.c:31:2: error: 'thread_env' undeclared (first use in this function)
  thread_env = env;\
  ^
jnlua.c:188:2: note: in expansion of macro 'JNLUA_ENV'
  JNLUA_ENV(env);

I'm sure that the include paths are correct, no idea why this happens. Highly appreciated that someone can help, I really need to compile it into dll file because the prebuild dll doesn't support windows XP.

Update on 22-Mar: My problem is finally resolved by following command, thanks for help:

gcc -m32 -Wl,--add-stdcall-alias -shared -O2 -o jnlua5.1.dll jnlua.c lua5.1.dll -DLUA_WIN -DLUA_BUILD_AS_DLL -Id:\luarock\lua -Id:\java\include\win32 -Id:\java\include -static -s
Tyler
  • 185
  • 5

2 Answers2

0

Judging by the source you probably need to define LUA_WIN.

I don't know much about this particular project, but you could try adding -DLUA_WIN to the compiler command.

Really, though, you should go and find some proper installation instructions, because there clearly ought to be some.

ams
  • 24,923
  • 4
  • 54
  • 75
0

In your "jnlua/src/main/c/Win32" directory you should find a Makefile in there. Though it's initially setup to use Visual Studio's cl compiler you can modify it so it works with Mingw.

For example, the following Makefile works on my setup:

# Makefile.mingw
# Paths
JDK_DIR=G:/jdk
LUA_DIR=G:/Luajit-2.1.0
LUA_INC=$(LUA_DIR)/include/luajit-2.1
VERSION=51

# Tools
CC=gcc
LD=gcc

# Default arguments
CFLAGS=-Wall -pedantic -O0 -DNDEBUG -DLUA_WIN
LDFLAGS=-shared

# Description blocks
all: jnlua$(VERSION).dll javavm.dll

jnlua$(VERSION).dll: jnlua.obj
  $(LD) $(LDFLAGS) -o $@ -L"$(LUA_DIR)" $^ -l:lua$(VERSION).dll

javavm.dll: javavm.obj
  $(LD) $(LDFLAGS) -o $@ -L"$(LUA_DIR)" -L"$(JDK_DIR)/lib" $^ -l:lua$(VERSION).dll -l:jvm.lib

jnlua.obj: ..\jnlua.c
  $(CC) $(CFLAGS) -DLUA_BUILD_AS_DLL -I"$(JDK_DIR)/include" -I"$(JDK_DIR)/include/win32" -I"$(LUA_INC)" -c -o $@ $^

javavm.obj: ..\javavm.c ..\javavm.h
  $(CC) $(CFLAGS) -DLUA_BUILD_AS_DLL -DLUA_LIB -I"$(JDK_DIR)/include" -I"$(JDK_DIR)/include/win32" -I"$(LUA_INC)" -c -o $@ $<

Then use the following make command:

mingw32-make -f Makefile.mingw -C src\main\c\Win32

If all goes well this will produce javavm.obj, jnlua.obj and their corresponding dll output javavm.dll and jnlua51.dll.

Make sure to change the JDK_DIR, LUA_DIR, LUA_INC and VERSION in the makefile as appropriate to fit your setup.

greatwolf
  • 20,287
  • 13
  • 71
  • 105
  • Thank you, but the jnlua.dll doesn't work. Exception in thread "main" java.lang.UnsatisfiedLinkError: com.naef.jnlua.LuaState.lua_version()Ljava/lang/String; at com.naef.jnlua.LuaState.lua_version(Native Method) at com.naef.jnlua.LuaState.(LuaState.java:116) – Tyler Feb 13 '15 at 06:55
  • There's also a `jnlua-0.9.6-native.zip` that has the dll's precompiled. Can you see if using those work? Note, you might need the msvcr runtime distiributable since they built it with msvc. – greatwolf Feb 13 '15 at 07:16
  • it doesn't support XP – Tyler Feb 13 '15 at 07:27