脚本来源:Demon's Blog,http://demon.tw/software/compile-lua-with-tcc.html 版权归原作者所有

使用方法:

1.下载tcc编译器,本文解压目录:C:\Program Files\tcc,

2.下载lua源码,本文解压到D:\lua-5.3.4

3.然后把这个脚本放到D:\lua-5.3.4目录运行

编译5.3.4过程中使用博客中的脚本会出现:tcc: error: undefined symbol 'luaopen_utf8'

原因是在链接/生成lua.exe/luac.exe过程中缺失了luaopen_utf8声明,声明在lutf8lib.c中,编译时把这个文件带入即可

@echo off
rem Author: Demon
rem Date: 2012/6/2
rem Website: http://demon.tw
set INSTALL_TOP=D:\lua-5.3.4
set INSTALL_BIN=%INSTALL_TOP%\bin
set INSTALL_INC=%INSTALL_TOP%\include
set INSTALL_LIB=%INSTALL_TOP%\lib
set PATH=C:\Program Files\tcc;%PATH%
if not exist %INSTALL_BIN% mkdir %INSTALL_BIN%
if not exist %INSTALL_INC% mkdir %INSTALL_INC%
if not exist %INSTALL_LIB% mkdir %INSTALL_LIB% cd src
tcc -r -o liblua.a lapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c lauxlib.c lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c lmathlib.c loslib.c lstrlib.c ltablib.c loadlib.c linit.c
rem 兼容5.3.4版本处理
type linit.c|find /i "luaopen_utf8">nul
if "%errorlevel%"=="0" (
tcc -o lua.exe liblua.a lua.c lutf8lib.c
tcc -o luac.exe liblua.a luac.c lutf8lib.c
) else (
tcc -o lua.exe liblua.a lua.c
tcc -o luac.exe liblua.a luac.c
) >nul copy lua.exe %INSTALL_BIN%
>nul copy luac.exe %INSTALL_BIN%
>nul copy liblua.a %INSTALL_LIB%
for %%i in (lua.h luaconf.h lualib.h lauxlib.h lua.hpp) do (
>nul copy %%i %INSTALL_INC%
)
%INSTALL_BIN%\lua.exe -i
05-11 09:41