编译tolua——4、更新luaJit

目录
1、编译工具和环境说明
2、基础编译tolua
3、以pbc为例子,添加第三方库
4、更新luaJit

大家好,我是阿赵。
用tolua做项目的朋友们,在这两年肯定会遇到过一个问题,就是现在的安卓应用市场比如谷歌市场,要求上传的应用发布时都选择target api=30以上。然后用tolua的旧项目打包之后,发现在安卓11以上的手机上,会闪退,具体报错是lua初始化时的bad light userdata pointer。
这个问题的答案网上也有很多了,既然之前写了几篇编译tolua的文章,我这里也记录一下,方便以后查看。
这个问题的解决办法其实很简单,只需要去下载最新的LuaJIT库并替换到tolua里面,重新编译一次就可以了。

一、下载最新的LuaJit库

下载地址
编译tolua——4、更新luaJit_第1张图片

看起来是一直还有人在维护的
在这里插入图片描述

下载下来对比一下,发现Copyright的时间也更新过了

二、复制替换文件

编译tolua——4、更新luaJit_第2张图片

把下载到的文件解压之后,复制到tolua编译项目的luajit-2.1文件夹里面

三、尝试编译

admin@DESKTOP-DL702DH MINGW64 ~ $ cd /g/

admin@DESKTOP-DL702DH MINGW64 /g $ cd tolua

admin@DESKTOP-DL702DH MINGW64 /g/tolua $ dir android
build_win32.sh iOS luasocket struct.c bit.c
build_win32x.sh LICENSE macjit tolua.c build_arm.sh
build_win64.sh link_arm64.bat macnojit tolua.h build_arm64.sh
build_win64x.sh link_arm64x.bat pb.c ubuntu build_ios.sh
build_x86.sh lpeg.c pbc uint64.c build_osx.sh
cjson lpeg.h Plugins window build_ubuntu.sh
int64.c luajit-2.1 README.md

admin@DESKTOP-DL702DH MINGW64 /g/tolua $ ./build_win64x.sh
E:/Software/msys64/mingw64/bin/mingw32-make -C src clean
mingw32-make[1]: Entering directory ‘G:/tolua/luajit-2.1/src’ rm -f
luajit.exe libluajit.a lua51.dll host/minilua.exe host/buildvm.exe
lj_vm.S lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h
host/buildvm_arch.h jit/vmdef.lua .o host/.o *.obj *.lib *.exp *.dll
*.exe *.manifest *.pdb *.ilk mingw32-make[1]: Leaving directory ‘G:/tolua/luajit-2.1/src’
==== Building LuaJIT 2.1.0-beta3 ==== E:/Software/msys64/mingw64/bin/mingw32-make -C src mingw32-make[1]:
Entering directory ‘G:/tolua/luajit-2.1/src’ HOSTCC host/minilua.o
HOSTLINK host/minilua.exe DYNASM host/buildvm_arch.h HOSTCC
host/buildvm.o HOSTCC host/buildvm_asm.o HOSTCC
host/buildvm_peobj.o HOSTCC host/buildvm_lib.o HOSTCC
host/buildvm_fold.o HOSTLINK host/buildvm.exe BUILDVM lj_vm.o CC
lj_assert.o CC lj_gc.o BUILDVM lj_ffdef.h CC lj_err.o
CC lj_char.o BUILDVM lj_bcdef.h CC lj_bc.o CC
lj_obj.o CC lj_buf.o CC lj_str.o CC lj_tab.o CC
lj_func.o CC lj_udata.o CC lj_meta.o CC
lj_debug.o CC lj_prng.o CC lj_state.o CC
lj_dispatch.o CC lj_vmevent.o CC lj_vmmath.o CC
lj_strscan.o CC lj_strfmt.o CC lj_strfmt_num.o CC
lj_serialize.o CC lj_api.o CC lj_profile.o CC
lj_lex.o CC lj_parse.o CC lj_bcread.o CC
lj_bcwrite.o CC lj_load.o CC lj_ir.o CC
lj_opt_mem.o BUILDVM lj_folddef.h CC lj_opt_fold.o CC
lj_opt_narrow.o CC lj_opt_dce.o CC lj_opt_loop.o CC
lj_opt_split.o CC lj_opt_sink.o CC lj_mcode.o CC
lj_snap.o CC lj_record.o CC lj_crecord.o BUILDVM
lj_recdef.h CC lj_ffrecord.o CC lj_asm.o CC
lj_trace.o CC lj_gdbjit.o CC lj_ctype.o CC
lj_cdata.o CC lj_cconv.o CC lj_ccall.o CC
lj_ccallback.o CC lj_carith.o CC lj_clib.o CC
lj_cparse.o CC lj_lib.o CC lj_alloc.o CC
lib_aux.o BUILDVM lj_libdef.h CC lib_base.o CC
lib_math.o CC lib_bit.o CC lib_string.o CC
lib_table.o CC lib_io.o CC lib_os.o CC
lib_package.o CC lib_debug.o CC lib_jit.o CC
lib_ffi.o CC lib_buffer.o CC lib_init.o AR
libluajit.a CC luajit.o BUILDVM jit/vmdef.lua LINK
luajit.exe OK Successfully built LuaJIT mingw32-make[1]:
Leaving directory ‘G:/tolua/luajit-2.1/src’
==== Successfully built LuaJIT 2.1.0-beta3 ==== E:/Software/msys64/mingw64/bin/mingw32-make -C src clean
mingw32-make[1]: Entering directory ‘G:/tolua/luajit-2.1/src’ rm -f
luajit.exe libluajit.a lua51.dll host/minilua.exe host/buildvm.exe
lj_vm.S lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h
host/buildvm_arch.h jit/vmdef.lua .o host/.o *.obj *.lib *.exp *.dll
*.exe *.manifest *.pdb *.ilk mingw32-make[1]: Leaving directory ‘G:/tolua/luajit-2.1/src’ tolua.c: In function ‘tolua_getvec2’:
tolua.c:114:2: warning: implicit declaration of function ‘lua_getref’
[-Wimplicit-function-declaration] lua_getref(L,
LUA_RIDX_UNPACKVEC2); ^ int64.c: In function ‘_isint64’:
int64.c:43:9: warning: implicit declaration of function ‘lua_getref’
[-Wimplicit-function-declaration]
lua_getref(L, LUA_RIDX_INT64);
^ uint64.c: In function ‘_isuint64’: uint64.c:43:9: warning: implicit declaration of function ‘lua_getref’
[-Wimplicit-function-declaration]
lua_getref(L, LUA_RIDX_UINT64);
^ pbc/binding/lua/pbc-lua.c:35:0: warning: “luaL_newlib” redefined #define luaL_newlib(L ,reg)
luaL_register(L,“protobuf.c”,reg) ^ In file included from
pbc/binding/lua/pbc-lua.c:6:0: luajit-2.1/src/lauxlib.h:125:0: note:
this is the location of the previous definition #define
luaL_newlib(L, l) (luaL_newlibtable(L, l), luaL_setfuncs(L, l, 0)) ^
E:\Software\msys64\tmp\ccr9bONS.o:tolua.c:(.text+0x17e): undefined
reference to lua_getref' E:\Software\msys64\tmp\ccr9bONS.o:tolua.c:(.text+0x215): undefined reference to lua_getref’
E:\Software\msys64\tmp\ccr9bONS.o:tolua.c:(.text+0x2a6): undefined
reference to lua_getref' E:\Software\msys64\tmp\ccr9bONS.o:tolua.c:(.text+0x12a2): undefined reference to lua_getref’
E:\Software\msys64\tmp\ccr9bONS.o:tolua.c:(.text+0x18b3): undefined
reference to lua_getref' E:\Software\msys64\tmp\ccr9bONS.o:tolua.c:(.text+0x193b): more undefined references to lua_getref’ follow collect2.exe: error: ld
returned 1 exit status

尝试编译一下,发现有错误,没有编译成功。

四、解决

因为报错undefined reference to `lua_getref’,证明lua_getref方法没有定义,找到旧版本的luajit搜索一下,发现之前是在luajit-2.1/src/lauxlib.h最后定义的

#define lua_unref(L,ref)        luaL_unref(L, LUA_REGISTRYINDEX, (ref))
#define lua_getref(L,ref)       lua_rawgeti(L, LUA_REGISTRYINDEX, (ref))

把这个添加到新复制进去的luajit对应文件里面,编译就通过了。

五、总结

通过解决这个错误,实际我们可以得出一些经验的。
虽然我们是在命令行编译,但实际上每一个命令的运行过程和结果都有在控制台输出。所以如果发现编译不成功,不要紧张,不要惊慌,我们应该仔细的分析一下打印输出,看具体是哪里有问题。
一般来说有几种可能:

1、工具或者编译的路径没指定
2、使用的编译版本不对,比如ndk不同版本的gcc问题
3、没有指定源码目录,导致文件include的时候找不到
4、某些需要使用的代码没有定义,具体看看报错是什么地方没定义,加上继续
5、某些代码重复定义,这个可以具体看看报错,比如某些方法在两个第三方库里面都提供了,导致重复了,这些一般在输出的报错里面都有具体重复的方法名,可以文件夹搜索,找出重复的方法并看情况删除其中一个
6、添加的源码有错误,导致编译不过。比如某个.c文件有编译不过地方,一般在输出的报错里面都有说明文件名和行号,可以具体的去分析一下源码是否有错误。

你可能感兴趣的:(Unity功能与问题解决,tolua,编译,luajit)