"Up-to-date" compilation of Luajit libraries for IOS and Android real machines and emulators

Source: Internet
Author: User
Tags lua

Compiling the Luajit library is indeed a challenge. Because the tutorials on the official website are not available in the current version of Xcode and NDK environments. Previously just compiled the Luajit library for the real machine. Recently in the attempt to compile the emulator Luajit Library, the way to comb the next Luajit Library compilation experience for later review. There are some of the online discussions, but quite a few are outdated. Perhaps when you see this article, you may just be able to get some possible experience to solve your own compilation problem. So, to understand some basic knowledge of compiling, can barely read Luajit make file, or is very necessary. This article is about Luajit static library, if you are looking for how to compile Luajit bytecode for mobile, you can see the "latest" Luajit 32/64 bit bytecode, from compile to use full record.

Compiling the environment

When you try to cross-compile the Luajit library yourself, you'll see how much the impact of the environment is.

    • MacOS 10.13.4

    • Xcode 9.4.1

    • Android Studio 3.1.3

    • The basic path information is first agreed to be used later

├── LuaJIT-2.1.0-beta3├── build-android.sh├── build-ios.sh├── lib│   ├── android│   │   ├── arm64-v8a│   │   ├── armeabi│   │   ├── armeabi-v7a│   │   └── x86│   └── ios│       └── libluajit2.1.0-beta.3.a
Compile the Luajit library for IOS, and you may encounter problems before compiling the preparation

Need to first put Luajit source of lj_arch.h 547 lines, from

#if LJ_TARGET_CONSOLE || (LJ_TARGET_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_8_0)#define LJ_NO_SYSTEM        1#endif

Switch

 #define LJ_NO_SYSTEM        1

Otherwise, an error is triggered:

./lib_os.c:52:14: error: ‘system‘ is unavailable: not available on iOS

The reason for the problem is that the judgment here is already in the latest Xcode-extremely-compiled environment and cannot fight for work. For children who are interested in the root cause of this problem, please read the Luajit make file yourself.

Note : When compiling Android or other platform libraries, there is no need to modify the source code here.

Full IOS compile command: build-ios.sh

It is advisable to execute directly on the command line in the way SH file is, and may trigger strange unknown problems. One of the key reasons is that when you copy and paste instructions, some text editors (such as notes on your Mac) get mixed up with special characters, which causes the compilation instructions to run unsuccessfully.

#!/bin/bash# Luajit Source Path luajit=./luajit-2.1.0-beta3xcodepath= ' Xcode-select-print-path ' DEVDIR= $XCODEPATH/ platformsiosver=iphoneos.sdksimver=iphonesimulator.sdk# Library's most general name libname=libluajit2.1.0-beta.3.a# IOS Minimum compatible version, preferably with the need to embed The minimum compatibility settings for Luajit apps remain the same. minversion=9.0iosdir= $DEVDIR/iphoneos.platform/developersimdir= $DEVDIR/iphonesimulator.platform/developer# Xctoolchain can be installed using the Xcode-select--install command. # xctoolchain and emulator, currently does not include the GCC and other commands, can be copied from the rest of the system to the $IOSBIN directory. # The specific path of the command can be performed XC Odebuild-find GCC obtained. iosbin= $XCODEPATH/toolchains/xcodedefault.xctoolchain/usr/bin/simbin= $SIMDIR/usr/bin/build_dir= $LUAJIT/build RM -RF $BUILD _dirmkdir-p $BUILD _dirrm *.a 1>/dev/null 2>/dev/null Echo =========================================== ======echo ARMV7 architectureisdkf= "-arch armv7-isysroot $IOSDIR/sdks/$IOSVER-miphoneos-version-min= $MINVERSION" Make-j-C $LUAJIT host_cc= "Gcc-m32" cross= $IOSBIN target_flags= "$ISDKF" Target=armv7 target_sys=ios cleanmake-j-C $LU AJIT host_cc= "Gcc-m32" cross= $IOSBIN target_flags= "$ISDKF" target=armv7 target_sys=ios mv $LUAJIT/src/libluajit.a $BUILD _dir/libluajita7.a Echo ========== =======================================echo ARM64 architectureisdkf= "-arch arm64-isysroot $IOSDIR/sdks/$IOSVER- miphoneos-version-min= $MINVERSION "Make-j-C $LUAJIT host_cc=" gcc "cross= $IOSBIN target_flags=" $ISDKF "target=arm64 Target_sys=ios Cleanmake-j-C $LUAJIT host_cc= "gcc" cross= $IOSBIN target_flags= "$ISDKF" target=arm64 target_sys=ios MV $ LUAJIT/SRC/LIBLUAJIT.A $BUILD _dir/libluajit64bit.a Echo =================================================echo IOS Simulator architectureisdkf= "-arch x86_64-isysroot $SIMDIR/sdks/$SIMVER-miphoneos-version-min= $MINVERSION" Make-j- C $LUAJIT host_cflags= "-arch x86_64" host_ldflags= "-arch x86_64" Target_sys=ios target=x86_64 cleanmake-j-C $LUAJIT HOST _cflags= "-arch x86_64" host_ldflags= "-arch x86_64" Target_sys=ios target=x86_64 amalg CROSS= $SIMBIN TARGET_FLAGS= "$ ISDKF "MV $LUAJIT/src/libluajit.a $BUILD _dir/libluajitx86_64.A Libtool-o $BUILD _dir/$LIBNAME $BUILD _dir/*.a 2>/dev/nullmkdir-p $BUILD _dir/headerscp $LUAJIT/src/lua.h $BUILD _ DIR/HEADERSCP $LUAJIT/src/lauxlib.h $BUILD _dir/headerscp $LUAJIT/src/lualib.h $BUILD _dir/headerscp $LUAJIT/src/ Luajit.h $BUILD _dir/headerscp $LUAJIT/src/lua.hpp $BUILD _dir/headerscp $LUAJIT/src/luaconf.h $BUILD _dir/headers MV $ build_dir/$LIBNAME./LIB/IOSRM-RF $BUILD _dircd $LUAJITmake cleancd.
Compile the script to run the method:
chmod a+x build-ios.sh./build-ios.sh
Other issues that may be encountered/APPLICATIONS/XCODE.APP/CONTENTS/DEVELOPER/PLATFORMS/TOOLCHAINS/XCODEDEFAULT.XCTOOLCHAIN/USR/BIN/GCC Command not Found

1> Install Toolchains First:

xcode-select --install

2> find the true path to the corresponding command on this computer:

xcodebuild -find gcc

3> if it can be found, copy the command to the location of the missing command, and if the machine cannot find it, search for the installation tutorial from the Internet.

Additional settings for the emulator
由于iphone5s以上虚拟机需要x86_64支持,luajit为了支持此模式需要在other linker flags中增加参数(注意,只需要对模拟器添加参数,针对ios不能添加,否则apple不会通过审核):-pagezero_size 10000 -image_base 100000000

Similar to the online description of a lot, but also very accurate, I would like to add: it is best to only in the Debug mode configuration to add the above special parameters.

Also, if you are already using Luajit bytecode, please note that the emulator Luajit library, which needs to be loaded with a byte-code.

Compile the Luajit library for Android, and you may encounter problems with the full Android compilation command: build-android.sh
#!/bin/bash# Luajit Source Path luajit=./luajit-2.1.0-beta3cd $LUAJIT # compile Android-x86make cleanndk=~/library/android/sdk/ ndk-bundlendkabi=17ndktriple=x86ndkver= $NDK/toolchains/$NDKTRIPLE -4.9ndkp= $NDKVER/prebuilt/darwin-x86_64/bin/ i686-linux-android-ndkf= "-isystem $NDK/sysroot/usr/include/i686-linux-android-d__android_api__= $NDKABI-D_FILE_ Offset_bits=32 "ndk_sysroot_build= $NDK/sysrootndk_sysroot_link= $NDK/platforms/android-$NDKABI/arch-x86make HOST_  Cc= "Gcc-4.9-m32" cross= $NDKP target_flags= "$NDKF" Target_sys=linux target_shldflags= "--sysroot $NDK _sysroot_link" target_ldflags= "--sysroot $NDK _sysroot_link" target_cflags= "--sysroot $NDK _sysroot_build" mv./src/libluajit.a ". /lib/android/x86/libluajit.a "#编译 Android-armeabimake cleanndk=~/library/android/sdk/ndk-bundlendkabi=17ndktriple =arm-linux-androideabindkver= $NDK/toolchains/$NDKTRIPLE -4.9ndkp= $NDKVER/prebuilt/darwin-x86_64/bin/$ ndktriple-ndkf= "-isystem $NDK/sysroot/usr/include/$NDKTRIPLE-d__android_api__= $NDKABI-d_file_offset_bits=32" NDK _sysroot_build= $NDK/sysrootndk_sysroot_link= $NDK/platforms/android-$NDKABI/arch-armmake host_cc= "Gcc-4.9-m32" cross= $NDKP target_flags= "$NDKF" Target_sys=linux target_shldflags= "--sysroot $NDK _sysroot_link" target_ldflags= "-- Sysroot $NDK _sysroot_link "target_cflags="--sysroot $NDK _sysroot_build "mv./src/libluajit.a. /lib/android/armeabi/libluajit.a# compiling Android-armeabi-v7amake cleanndk=~/library/android/sdk/ndk-bundlendkabi= 17ndktriple=arm-linux-androideabindkver= $NDK/toolchains/$NDKTRIPLE -4.9ndkp= $NDKVER/prebuilt/darwin-x86_64/bin/ $NDKTRIPLE-ndkf= "-isystem $NDK/sysroot/usr/include/$NDKTRIPLE-d__android_api__= $NDKABI-d_file_offset_bits=32" ndk_sysroot_build= $NDK/sysrootndk_sysroot_link= $NDK/platforms/android-$NDKABI/arch-armndkarch= "-march=armv7-a- MFLOAT-ABI=SOFTFP-WL,--fix-cortex-a8 "Make host_cc=" Gcc-4.9-m32 "cross= $NDKP target_flags=" $NDKF $NDKARCH "target_ Sys=linux target_shldflags= "--sysroot $NDK _sysroot_link" target_ldflags= "--sysroot $NDK _sysroot_link" TARGET_CFLAGS = "--sysroOT $NDK _sysroot_build "mv./src/libluajit.a. /lib/android/armeabi-v7a/libluajit.a# compiling Android-arm64-v8amake cleanndk=~/library/android/sdk/ndk-bundlendkabi= 21ndktriple=aarch64-linux-androidndkver= $NDK/toolchains/$NDKTRIPLE -4.9ndkp= $NDKVER/prebuilt/darwin-x86_64/bin/ $NDKTRIPLE-ndkf= "-isystem $NDK/sysroot/usr/include/$NDKTRIPLE-d__android_api__= $NDKABI" ndk_sysroot_build= $NDK/ sysrootndk_sysroot_link= $NDK/platforms/android-$NDKABI/arch-arm64make host_cc= "gcc-4.9" cross= $NDKP target_flags= "$NDKF" Target_sys=linux target_shldflags= "--sysroot $NDK _sysroot_link" target_ldflags= "--sysroot $NDK _sysroot_link "Target_cflags="--sysroot $NDK _sysroot_build "mv./src/libluajit.a. /lib/android/arm64-v8a/libluajit.amake Clean

Note: arm64-v8a,armeabi-v7a,Armeabi,x86 Four CPU architectures are compiled here. One of the arm64-v8a is not used because it causes a strange compatibility adaptation problem. The initial suspicion and the different manufacturers of the magic ROM implementation. Looking forward to see the little friends further in-depth interpretation ~

Reference article:
    • https://github.com/rampantpixels/lua_lib/blob/master/lua/luajit/build-ios.sh

    • https://github.com/cailei/luajit/blob/master/build-luajit-ios.sh

    • 43482109

    • Https://www.cnblogs.com/HemJohn/p/5429041.html

    • Https://www.jianshu.com/p/308d7be8b8df

    • https://stackoverflow.com/a/12228575

    • http://www.codexiu.cn/android/blog/14563/

    • Https://github.com/twilio/twilio-boost-build/issues/1

"Up-to-date" compilation of Luajit libraries for IOS and Android real machines and emulators

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.