前置要求:电脑已经设置好了Cmake能够使用
首先下载Lua源码,文件后缀是tar.gz
各版本可以从这里找到:Lua - Version history
解压下载文件至所需目录,文件内容如下图:
解压即可。
在解压的文件夹(本例是lua-5.3.6
)下建立文件CMakeLists.txt
内容是(参考自官网百科构建lua):
PROJECT ( lua )
IF( NOT WIN32 )
message( FATAL_ERROR "Written for window only" )
ENDIF()
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
# remove warnings
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS )
SET (HDR_LIBLUA
src/lapi.h src/lauxlib.h src/lcode.h src/lctype.h src/ldebug.h src/ldo.h src/lfunc.h
src/lgc.h src/llex.h src/llimits.h src/lmem.h src/lobject.h src/lopcodes.h src/lparser.h
src/lstate.h src/lstring.h src/ltable.h src/ltm.h src/lua.h src/luaconf.h src/lualib.h
src/lundump.h src/lvm.h src/lzio.h
)
#SET_SOURCE_FILES_PROPERTIES(${HDR_LIBLUA} PROPERTIES HEADER_FILE_ONLY TRUE)
#include_directories(src)
# Build Libraries
SET (SRC_LIBLUA
src/lapi.c src/lauxlib.c src/lbaselib.c src/lbitlib.c src/lcode.c src/lcorolib.c
src/lctype.c src/ldblib.c src/ldebug.c src/ldo.c src/ldump.c src/lfunc.c src/lgc.c
src/linit.c src/liolib.c src/llex.c src/lmathlib.c src/lmem.c src/loadlib.c src/lobject.c
src/lopcodes.c src/loslib.c src/lparser.c src/lstate.c src/lstring.c src/lstrlib.c
src/ltable.c src/ltablib.c src/ltm.c src/lundump.c src/lvm.c src/lzio.c
)
SET ( SRC_LUA src/lua.c )
SET ( SRC_LUAC src/luac.c )
# compile with C++ compiler
set_source_files_properties(${SRC_LIBLUA} ${SRC_LUA} ${SRC_LUAC} PROPERTIES LANGUAGE CXX)
# append headers to sources to make them show up in MSVC GUI
LIST(APPEND SRC_LIBLUA ${HDR_LIBLUA})
#Library
ADD_LIBRARY ( lualib ${SRC_LIBLUA} )
#DLL
ADD_LIBRARY ( lua5.2 SHARED ${SRC_LIBLUA} )
SET_TARGET_PROPERTIES (lua5.2 PROPERTIES DEFINE_SYMBOL "LUA_BUILD_AS_DLL" )
#exe
ADD_EXECUTABLE ( lua ${SRC_LUA} )
ADD_EXECUTABLE ( luac ${SRC_LUAC} )
#lua uses a DLL; luac uses a library
TARGET_LINK_LIBRARIES ( lua lua5.2 )
TARGET_LINK_LIBRARIES ( luac lualib )
改一下里面的版本号,然后cmake
一下就行,代码是
cmake -G "Visual Studio 16"
版本改成自己的,我是vs2019就改成16,其余版本见下图
然后打开生成的.sln
文件,依次右键生成各项目,注意配置使用release而不是debug
获得luac.exe``和·lua.exe
等文件,其余为环境变量配置,网上都有,自行百度。