Compile tolua——4. Update luaJit

Contents
1. Compilation tools and environment instructions
2. Basic compilation of tolua
3. Taking pbc as an example, add third-party libraries
4. Update luaJit

Hello everyone, I am Zhao.
Friends who use tolua for projects must have encountered a problem in the past two years, that is, the current Android application market, such as Google Market, requires uploaded applications to select target api=30 or above when publishing. Then after packaging with the old project of tolua, it was found that on the mobile phone above Android 11, it will flash back. The specific error is the bad light userdata pointer when lua is initialized.
There are also many answers to this question on the Internet. Since I have written several articles about compiling tolua before, I will also record them here for future reference.
The solution to this problem is actually very simple, just download the latest LuaJIT library and replace it into tolua, and recompile it once.

1. Download the latest LuaJit library

download link
insert image description here

Looks like it's still being maintained
insert image description here

Download it and compare it, and found that the copyright time has also been updated

Second, copy the replacement file

insert image description here

After decompressing the downloaded file, copy it to the luajit-2.1 folder of the tolua compilation project

3. Try to compile

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

Try to compile it and find that there is an error, but the compilation is not successful.

Four, solve

Because the error undefined reference to `lua_getref' is reported, it proves that the lua_getref method is not defined, find the old version of luajit and search, and found that it was defined last in 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))

Add this to the newly copied luajit corresponding file, and the compilation will pass.

V. Summary

By solving this error, we can actually draw some experience.
Although we are compiling on the command line, in fact, the running process and results of each command are output on the console. So if you find that the compilation is unsuccessful, don't be nervous, don't panic, we should carefully analyze the printout to see where there is a problem.
In general there are several possibilities:

1. The tool or compilation path is not specified.
2. The compiled version used is incorrect, such as the gcc problem of different versions of ndk.
3. The source code directory is not specified, resulting in the file not being found when the file is included.
4. Some codes that need to be used are not defined. Specifically look at where the error is not defined, plus continue
5, some codes are repeatedly defined, this can be specifically looked at the error, for example, some methods are provided in two third-party libraries, resulting in duplication, these are generally in There are specific repeated method names in the output error report. You can search the folder to find the repeated method and delete one of them depending on the situation.
6. The added source code has errors, which cause the compilation to fail. For example, if a certain .c file cannot be compiled, the output error report generally contains a description of the file name and line number, so you can analyze the source code specifically for errors.

Guess you like

Origin blog.csdn.net/liweizhao/article/details/131144050