windows安装mingw和LuaJIT

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

你可能感兴趣的:(windows安装mingw和LuaJIT)