Windows下的lua-5.3.4安装过程
Mingw平台下的编译过程:
$ make echo
$ make mingw
$ make local
$ make echo PLAT= none CC= gcc -std=gnu99 CFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_2 LDFLAGS= LIBS= -lm AR= ar rcu RANLIB= ranlib RM= rm -f PLAT= none V= 5.3 R= 5.3.4 TO_BIN= lua luac TO_INC= lua.h luaconf.h lualib.h lauxlib.h lua.hpp TO_LIB= liblua.a TO_MAN= lua.1 luac.1 INSTALL_TOP= /usr/local INSTALL_BIN= /usr/local/bin INSTALL_INC= /usr/local/include INSTALL_LIB= /usr/local/lib INSTALL_MAN= /usr/local/man/man1 INSTALL_LMOD= /usr/local/share/lua/5.3 INSTALL_CMOD= /usr/local/lib/lua/5.3 INSTALL_EXEC= install -p -m 0755 INSTALL_DATA= install -p -m 0644 $ make mingw cd src && make mingw make[1]: Entering directory `/d/lua-5.3.4/src' make "LUA_A=lua53.dll" "LUA_T=lua.exe" "AR=gcc -std=gnu99 -shared -o" "RANLIB=strip --strip-unneeded" "SYSCFLAGS=-DLUA_BUILD_AS_DLL" "SYSLIBS=" "SYSLDFLAGS=-s" lua.exe make[2]: Entering directory `/d/lua-5.3.4/src' gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lua.o lua.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lapi.o lapi.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lcode.o lcode.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lctype.o lctype.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o ldebug.o ldebug.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o ldo.o ldo.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o ldump.o ldump.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lfunc.o lfunc.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lgc.o lgc.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o llex.o llex.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lmem.o lmem.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lobject.o lobject.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lopcodes.o lopcodes.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lparser.o lparser.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lstate.o lstate.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lstring.o lstring.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o ltable.o ltable.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o ltm.o ltm.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lundump.o lundump.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lvm.o lvm.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lzio.o lzio.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lauxlib.o lauxlib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lbaselib.o lbaselib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lbitlib.o lbitlib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lcorolib.o lcorolib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o ldblib.o ldblib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o liolib.o liolib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lmathlib.o lmathlib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o loslib.o loslib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lstrlib.o lstrlib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o ltablib.o ltablib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o lutf8lib.o lutf8lib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o loadlib.o loadlib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_BUILD_AS_DLL -c -o linit.o linit.c gcc -std=gnu99 -shared -o lua53.dll lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o lmathlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o loadlib.o linit.o strip --strip-unneeded lua53.dll gcc -std=gnu99 -o lua.exe -s lua.o lua53.dll -lm make[2]: Leaving directory `/d/lua-5.3.4/src' make "LUAC_T=luac.exe" luac.exe make[2]: Entering directory `/d/lua-5.3.4/src' gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -c -o luac.o luac.c ar rcu liblua.a lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o lmathlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o loadlib.o linit.o ranlib liblua.a gcc -std=gnu99 -o luac.exe luac.o liblua.a -lm make[2]: Leaving directory `/d/lua-5.3.4/src' make[1]: Leaving directory `/d/lua-5.3.4/src' $ make local make install INSTALL_TOP=../install make[1]: Entering directory `/d/lua-5.3.4' cd src && mkdir -p ../install/bin ../install/include ../install/lib ../install/man/man1 ../install/share/lua/5.3 ../install/lib/lua/5.3 cd src && install -p -m 0755 lua luac ../install/bin cd src && install -p -m 0644 lua.h luaconf.h lualib.h lauxlib.h lua.hpp ../install/include cd src && install -p -m 0644 liblua.a ../install/lib cd doc && install -p -m 0644 lua.1 luac.1 ../install/man/man1 make[1]: Leaving directory `/d/lua-5.3.4'
安装目录结构
D:LUA-5.3.4INSTALL ├─bin │ lua.exe │ luac.exe │ ├─include │ lauxlib.h │ lua.h │ lua.hpp │ luaconf.h │ lualib.h │ ├─lib │ │ liblua.a │ │ │ └─lua │ └─5.3 ├─man │ └─man1 │ lua.1 │ luac.1 │ └─share └─lua
MSVC 命令行编译脚本:
md bin md include md lib cd src cl /c /nologo /W3 /O2 /Ob1 /Oi /Gs /MD *.c del lua.obj luac.obj link /LIB /out:lua53.lib /verbose:lib *.obj copy lua53.lib ..liblua53.lib del *.obj *.lib *.dll *.exp cd .. echo Compile lua53.lib successfully... cd src cl /c /nologo /W3 /O2 /Ob1 /Oi /Gs /MD /DLUA_BUILD_AS_DLL /D_CRT_SECURE_NO_DEPRECATE *.c del lua.obj luac.obj link /DLL /out:lua53.dll /verbose:lib *.obj copy lua53.dll ..liblua53.dll del *.obj *.lib *.dll *.exp cd .. echo Compile lua53.dll successfully... cd src cl /c /nologo /W3 /O2 /Ob1 /Oi /Gs /MD *.c del luac.obj link /out:lua53.exe /verbose:lib *.obj copy lua53.exe ..inlua53.exe del *.obj *.lib *.dll *.exp *.exe cd .. echo Compile lua53.exe successfully... cd src cl /c /nologo /W3 /O2 /Ob1 /Oi /Gs /MD *.c del lua.obj link /out:luac53.exe /verbose:lib *.obj copy luac53.exe ..inluac53.exe del *.obj *.lib *.dll *.exp *.exe cd .. echo Compile luac53.exe successfully... cd src copy lauxlib.h ..includelauxlib.h copy lua.h ..includelua.h copy lua.hpp ..includelua.hpp copy luaconf.h ..includeluaconf.h copy lualib.h ..includelualib.h cd .. echo Copy lua include file successfully...
打开 【VS2012 开发人员命令提示】
手动编译过程
D:lua-5.3.4>md bin D:lua-5.3.4>md include D:lua-5.3.4>md lib D:lua-5.3.4>cd src D:lua-5.3.4src>cl /c /nologo /W3 /O2 /Ob1 /Oi /Gs /MD *.c lapi.c lauxlib.c lbaselib.c lbitlib.c lcode.c lcorolib.c lctype.c ldblib.c ldebug.c ldo.c ldump.c lfunc.c lgc.c linit.c liolib.c llex.c lmathlib.c lmem.c loadlib.c lobject.c 正在生成代码... 正在编译... lopcodes.c loslib.c lparser.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c ltm.c lua.c luac.c lundump.c lutf8lib.c lvm.c lzio.c 正在生成代码... D:lua-5.3.4src>del lua.obj luac.obj D:lua-5.3.4src>link /LIB /out:lua53.lib /verbose:lib *.obj Microsoft (R) Library Manager Version 11.00.61030.0 Copyright (C) Microsoft Corporation. All rights reserved. D:lua-5.3.4src>copy lua53.lib ..liblua53.lib 已复制 1 个文件。 D:lua-5.3.4src>del *.obj *.lib *.dll *.exp D:lua-5.3.4src>cd .. D:lua-5.3.4>echo Compile lua53.lib successfully... Compile lua53.lib successfully... D:lua-5.3.4>cd src D:lua-5.3.4src>cl /c /nologo /W3 /O2 /Ob1 /Oi /Gs /MD /DLUA_BUILD_AS_DLL /D_CRT_SECURE_NO_DEPRECATE *.c lapi.c lauxlib.c lbaselib.c lbitlib.c lcode.c lcorolib.c lctype.c ldblib.c ldebug.c ldo.c ldump.c lfunc.c lgc.c linit.c liolib.c llex.c lmathlib.c lmem.c loadlib.c lobject.c 正在生成代码... 正在编译... lopcodes.c loslib.c lparser.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c ltm.c lua.c luac.c lundump.c lutf8lib.c lvm.c lzio.c 正在生成代码... D:lua-5.3.4src>del lua.obj luac.obj D:lua-5.3.4src>link /DLL /out:lua53.dll /verbose:lib *.obj Microsoft (R) Incremental Linker Version 11.00.61030.0 Copyright (C) Microsoft Corporation. All rights reserved. 正在搜索库 正在搜索 C:Program Files (x86)Microsoft Visual Studio 11.0VCLIBMSVCRT.lib: 正在搜索 C:Program Files (x86)Microsoft Visual Studio 11.0VCLIBOLDNAMES.lib: 正在搜索 C:Program Files (x86)Windows Kits8.0libwin8umx86uuid.lib: 正在搜索 C:Program Files (x86)Windows Kits8.0libwin8umx86kernel32.lib: 正在搜索 C:Program Files (x86)Microsoft Visual Studio 11.0VCLIBMSVCRT.lib: 正在搜索 C:Program Files (x86)Microsoft Visual Studio 11.0VCLIBOLDNAMES.lib: 正在搜索 C:Program Files (x86)Windows Kits8.0libwin8umx86uuid.lib: 已完成库搜索 正在创建库 lua53.lib 和对象 lua53.exp 正在搜索库 正在搜索 C:Program Files (x86)Microsoft Visual Studio 11.0VCLIBMSVCRT.lib: 正在搜索 C:Program Files (x86)Microsoft Visual Studio 11.0VCLIBOLDNAMES.lib: 正在搜索 C:Program Files (x86)Windows Kits8.0libwin8umx86uuid.lib: 正在搜索 C:Program Files (x86)Windows Kits8.0libwin8umx86kernel32.lib: 已完成库搜索 正在搜索库 正在搜索 C:Program Files (x86)Microsoft Visual Studio 11.0VCLIBMSVCRT.lib: 正在搜索 C:Program Files (x86)Microsoft Visual Studio 11.0VCLIBOLDNAMES.lib: 正在搜索 C:Program Files (x86)Windows Kits8.0libwin8umx86uuid.lib: 正在搜索 C:Program Files (x86)Windows Kits8.0libwin8umx86kernel32.lib: 已完成库搜索 D:lua-5.3.4src>copy lua53.dll ..liblua53.dll 已复制 1 个文件。 D:lua-5.3.4src>del *.obj *.lib *.dll *.exp D:lua-5.3.4src>cd .. D:lua-5.3.4>echo Compile lua53.dll successfully... Compile lua53.dll successfully... D:lua-5.3.4>cd src D:lua-5.3.4src>cl /c /nologo /W3 /O2 /Ob1 /Oi /Gs /MD *.c lapi.c lauxlib.c lbaselib.c lbitlib.c lcode.c lcorolib.c lctype.c ldblib.c ldebug.c ldo.c ldump.c lfunc.c lgc.c linit.c liolib.c llex.c lmathlib.c lmem.c loadlib.c lobject.c 正在生成代码... 正在编译... lopcodes.c loslib.c lparser.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c ltm.c lua.c luac.c lundump.c lutf8lib.c lvm.c lzio.c 正在生成代码... D:lua-5.3.4src>del luac.obj D:lua-5.3.4src>link /out:lua53.exe /verbose:lib *.obj Microsoft (R) Incremental Linker Version 11.00.61030.0 Copyright (C) Microsoft Corporation. All rights reserved. 正在搜索库 正在搜索 C:Program Files (x86)Microsoft Visual Studio 11.0VCLIBMSVCRT.lib: 正在搜索 C:Program Files (x86)Microsoft Visual Studio 11.0VCLIBOLDNAMES.lib: 正在搜索 C:Program Files (x86)Windows Kits8.0libwin8umx86uuid.lib: 正在搜索 C:Program Files (x86)Windows Kits8.0libwin8umx86kernel32.lib: 正在搜索 C:Program Files (x86)Microsoft Visual Studio 11.0VCLIBMSVCRT.lib: 正在搜索 C:Program Files (x86)Microsoft Visual Studio 11.0VCLIBOLDNAMES.lib: 正在搜索 C:Program Files (x86)Windows Kits8.0libwin8umx86uuid.lib: 已完成库搜索 正在搜索库 正在搜索 C:Program Files (x86)Microsoft Visual Studio 11.0VCLIBMSVCRT.lib: 正在搜索 C:Program Files (x86)Microsoft Visual Studio 11.0VCLIBOLDNAMES.lib: 正在搜索 C:Program Files (x86)Windows Kits8.0libwin8umx86uuid.lib: 正在搜索 C:Program Files (x86)Windows Kits8.0libwin8umx86kernel32.lib: 已完成库搜索 D:lua-5.3.4src>copy lua53.exe ..inlua53.exe 已复制 1 个文件。 D:lua-5.3.4src>del *.obj *.lib *.dll *.exp *.exe D:lua-5.3.4src>cd .. D:lua-5.3.4>echo Compile lua53.exe successfully... Compile lua53.exe successfully... D:lua-5.3.4>cd src D:lua-5.3.4src>cl /c /nologo /W3 /O2 /Ob1 /Oi /Gs /MD *.c lapi.c lauxlib.c lbaselib.c lbitlib.c lcode.c lcorolib.c lctype.c ldblib.c ldebug.c ldo.c ldump.c lfunc.c lgc.c linit.c liolib.c llex.c lmathlib.c lmem.c loadlib.c lobject.c 正在生成代码... 正在编译... lopcodes.c loslib.c lparser.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c ltm.c lua.c luac.c lundump.c lutf8lib.c lvm.c lzio.c 正在生成代码... D:lua-5.3.4src>del lua.obj D:lua-5.3.4src>link /out:luac53.exe /verbose:lib *.obj Microsoft (R) Incremental Linker Version 11.00.61030.0 Copyright (C) Microsoft Corporation. All rights reserved. 正在搜索库 正在搜索 C:Program Files (x86)Microsoft Visual Studio 11.0VCLIBMSVCRT.lib: 正在搜索 C:Program Files (x86)Microsoft Visual Studio 11.0VCLIBOLDNAMES.lib: 正在搜索 C:Program Files (x86)Windows Kits8.0libwin8umx86uuid.lib: 正在搜索 C:Program Files (x86)Windows Kits8.0libwin8umx86kernel32.lib: 正在搜索 C:Program Files (x86)Microsoft Visual Studio 11.0VCLIBMSVCRT.lib: 正在搜索 C:Program Files (x86)Microsoft Visual Studio 11.0VCLIBOLDNAMES.lib: 正在搜索 C:Program Files (x86)Windows Kits8.0libwin8umx86uuid.lib: 已完成库搜索 正在搜索库 正在搜索 C:Program Files (x86)Microsoft Visual Studio 11.0VCLIBMSVCRT.lib: 正在搜索 C:Program Files (x86)Microsoft Visual Studio 11.0VCLIBOLDNAMES.lib: 正在搜索 C:Program Files (x86)Windows Kits8.0libwin8umx86uuid.lib: 正在搜索 C:Program Files (x86)Windows Kits8.0libwin8umx86kernel32.lib: 已完成库搜索 D:lua-5.3.4src>copy luac53.exe ..inluac53.exe 已复制 1 个文件。 D:lua-5.3.4src>del *.obj *.lib *.dll *.exp *.exe D:lua-5.3.4src>cd .. D:lua-5.3.4>echo Compile luac53.exe successfully... Compile luac53.exe successfully... D:lua-5.3.4>cd src D:lua-5.3.4src>copy lauxlib.h ..includelauxlib.h 已复制 1 个文件。 D:lua-5.3.4src>copy lua.h ..includelua.h 已复制 1 个文件。 D:lua-5.3.4src>copy lua.hpp ..includelua.hpp 已复制 1 个文件。 D:lua-5.3.4src>copy luaconf.h ..includeluaconf.h 已复制 1 个文件。 D:lua-5.3.4src>copy lualib.h ..includelualib.h 已复制 1 个文件。 D:lua-5.3.4src>cd .. D:lua-5.3.4>echo Copy lua include file successfully... Copy lua include file successfully...
生成文件列表
VS中BanbeLua配置
Lua简单的测试代码:
function babe_tostring(...) local num = select("#", ...); local args = { ...}; local outs = { }; for i = 1, num do if i > 1 then outs[#outs + 1] = " "; end outs[#outs + 1] = tostring(args[i]); end return table.concat(outs); end local babe_print = print; local babe_output = function(...) babe_print(...); if decoda_output ~= nil then local str = babe_tostring(...); decoda_output(str); end end babe_print("hello"); babe_output("Hello world, from ",_VERSION,"! "); os.execute("pause");
调试运行效果:
MSVS的工程属性配置
简单测试代码
#include <iostream> #include <lua.hpp> int main() { lua_State *L = luaL_newstate(); luaL_openlibs(L); if (0 != luaL_dofile(L, "main.lua")) { std::cout << lua_tostring(L, -1) << std::endl; } std::cout << "..." << std::endl; system("pause"); return 0; }
function babe_tostring(...) local num = select("#", ...); local args = { ...}; local outs = { }; for i = 1, num do if i > 1 then outs[#outs + 1] = " "; end outs[#outs + 1] = tostring(args[i]); end return table.concat(outs); end local babe_print = print; local babe_output = function(...) babe_print(...); if decoda_output ~= nil then local str = babe_tostring(...); decoda_output(str); end end babe_print("hello"); babe_print("你好"); babe_output("Hello world, from ",_VERSION,"! "); -- 单行注释 --[=[ 多行注释 1 ]=] --[[ 多行注释 2 --]] --os.execute("pause");
运行现象:
include files:
C:Program Files (x86)Microsoft Visual Studio 11.0VCinclude;
C:Program Files (x86)Microsoft Visual Studio 11.0VCatlmfcinclude;
C:Program Files (x86)Windows Kits8.0Includeum;
C:Program Files (x86)Windows Kits8.0Includeshared;
C:Program Files (x86)Windows Kits8.0Includewinrt;
C:WinDDK7600.16385.1inc;
C:QtQt5.5.15.5msvc2012include;
C:lua-5.3.4include;
D:opensslopenssl-1.0.2minclude;
source files:
C:Program Files (x86)Microsoft Visual Studio 11.0VCatlmfcsrcmfc;
C:Program Files (x86)Microsoft Visual Studio 11.0VCatlmfcsrcmfcm;
C:Program Files (x86)Microsoft Visual Studio 11.0VCatlmfcsrcatl;
C:Program Files (x86)Microsoft Visual Studio 11.0VCcrtsrc;
C:WinDDK7600.16385.1src;
C:QtQt5.5.15.5Src;
C:lua-5.3.4src;
D:opensslsourceopenssl-1.0.2m;