windows安裝mingw和LuaJIT

墮落門徒發表於2019-05-15

1,安裝mingw64

先下載mingw64壓縮包(不建議下載exe安裝包,線上安裝太慢),地址如下:

https://nchc.dl.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/seh/x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z

下載之後解壓到某路徑,然後將其中的bin路徑新增至系統path路徑,例如E:\Program Files\mingw64\bin

檢查是否安裝成功:

C:\Users\cord>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=E:/Program\ Files/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/8.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
......
Thread model: posix
gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)

2,編譯安裝luajit

下載luajit:http://luajit.org/download/LuaJIT-2.1.0-beta3.zip

解壓LuaJIT-2.1.0-beta3.zip並用cmd進入資料夾執行編譯命令mingw32-make

E:\>cd LuaJIT-2.1.0-beta3

E:\LuaJIT-2.1.0-beta3>mingw32-make
"==== Building LuaJIT 2.1.0-beta3 ===="
mingw32-make -C src
mingw32-make[1]: Entering directory 'E:/LuaJIT-2.1.0-beta3/src'
"HOSTCC    host/minilua.o"
.......
"CC        lj_lib.o"
"CC        lj_alloc.o"
lj_alloc.c:154:14: warning: 'DIRECT_MMAP' defined but not used [-Wunused-function]
 static void *DIRECT_MMAP(size_t size)
              ^~~~~~~~~~~
...              
"CC        lib_init.o"
"DYNLINK   lua51.dll"
"CC        luajit.o"
"BUILDVM   jit/vmdef.lua"
"LINK      luajit.exe"
"OK        Successfully built LuaJIT"
mingw32-make[1]: Leaving directory 'E:/LuaJIT-2.1.0-beta3/src'
"==== Successfully built LuaJIT 2.1.0-beta3 ===="

編譯完成之後,將src下面的luajit.exelua51.dll兩個檔案拷貝到新建的E:/LuaJIT資料夾下面,並將src下面的jit資料夾拷貝到E:/LuaJIT/lua下面,整體目錄結構如下:

E:\>tree /F luajit
卷 E 的資料夾 PATH 列表
卷序列號為 5EA5-2C1D
E:\LUAJIT
│  lua51.dll
│  luajit.exe
│
└─lua
    └─jit
            bc.lua
            bcsave.lua
            dis_arm.lua
            dis_arm64.lua
            dis_arm64be.lua
            dis_mips.lua
            dis_mips64.lua
            dis_mips64el.lua
            dis_mipsel.lua
            dis_ppc.lua
            dis_x64.lua
            dis_x86.lua
            dump.lua
            p.lua
            v.lua
            vmdef.lua
            zone.lua

最後將E:/LuaJIT加入path路徑。

檢驗安裝結果:

C:\Users\cord>luajit -v
LuaJIT 2.1.0-beta3 -- Copyright (C) 2005-2017 Mike Pall. http://luajit.org/

測試:

建立一個lua指令碼test.lua

print("hello world")

然後使用luajit進行編譯生成bytecode :

E:\Test\lua>luajit -b test.lua 1.lua

會發現路徑下生成了1.lua的檔案

:如果使用luajit的時候出現luajit: unknown luaJIT command or jit.* modules not installed的錯誤,說明lua模組放置的路徑有問題,可以通過luajit -e "require('jit.bcsave')"命令測試一下luajit的模組搜尋路徑:

E:\Test\lua>luajit -e "require('jit.bcsave')"
luajit: (command line):1: module 'jit.bcsave' not found:
        no field package.preload['jit.bcsave']
        no file '.\jit\bcsave.lua'
        no file 'E:\LuaJIT\lua\jit\bcsave.lua'
        no file 'E:\LuaJIT\lua\jit\bcsave\init.lua'
        no file '.\jit\bcsave.dll'
        no file 'E:\LuaJIT\jit\bcsave.dll'
        no file 'E:\LuaJIT\loadall.dll'
        no file '.\jit.dll'
        no file 'E:\LuaJIT\jit.dll'
        no file 'E:\LuaJIT\loadall.dll'
stack traceback:
        [C]: in function 'require'
        (command line):1: in main chunk
        [C]: at 0x00402060

也就是安裝後的jit資料夾最好放到編譯包luajit.exe的同級包的lua資料夾下

參考連結:

https://tutel.me/c/programming/questions/44166483/luajit+on+windows+10+unknown+luajit+command+or+jit

https://blog.csdn.net/mydreamremindme/article/details/51372391

相關文章