This article describes two types of Lua source code compilation, command-line compilation and VS compilation, taking the current latest lua-5.3.5 as an example, download and install VS2015 before you start compiling.
Download Lua source code
Command-line compilation
Extracting LUA Source code
Create a batch file in the root directory Msvc_build.bat
-
To open the file and write to the following command:
@echo OFFMD binmd libmd includecd srccl/c/nologo/w3/o2/ob1/oi/ Gs/md/d_crt_secure_no_deprecate l*.cren lua.obj lua.oren luac.obj luac.olib/out:lua53.lib *.objcopy lua53.lib. \lib\lua53.libdel *.o *.obj *.exp *.lib *.dll *.execl/c/nologo/w3/o2/ob1/oi/gs/md/d_crt_secure_no_deprecate/dlua _build_as_dll l*.cren lua.obj lua.oren luac.obj luac.olink/dll/implib:lua53.lib/out:lua53.dll *.objlink/out: Lua53.exe lua.o lua53.liblink/out:luac53.exe luac.o *.objcopy lua53.exp. \bin\lua53.expcopy Lua53.lib. \bin\lua53.libcopy Lua53.dll. \bin\lua53.dllcopy Lua53.exe. \bin\lua53.execopy Luac53.exe. \bin\luac53.exedel *.o *.obj *.exp *.lib *.dll *.execopy lauxlib.h. \include\lauxlib.hcopy lua.h. \include\lua.hcopy lua.hpp. \include\lua.hppcopy luaconf.h. \include\luaconf.hcopy Lualib.h. \INCLUDE\LUALIB.HCD. \
Open: Starting with Visual Studio, VS2015 developer command prompt, CD to Lua source root directory
Run Msvc_build.bat and wait for the result to compile, with the following results:
Compiling with VS2015
Creates an empty project lua53
, which is lua.c
added to the project.
解决方案'lua53'
under Add a new Win 32 project luadll
: In the Boot pop-up window select Next, the application type Select DLL, additional options to select the Empty project, click Finish, lua.c
and luac.c
add all the files to the project.
To lua53
add a reference to a project, method:
lua53
Add the directory containing the directory to the luadll
header file for the project, method:
To luadll
change the output file name to Lua53, method:
To luadll
add a preprocessor definition LUA_BUILD_AS_DLL
, method:
Add a new empty project under Solution ' Lua53 ' luac53
and lua.c
add all other files to the project.
Select individually lua53
luac53
and right-click to build the project.
The resulting results are as follows:
Problems encountered and their solutions
Luadll the. lib file was not generated at compile time, workaround: Add the preprocessor definition LUA_BUILD_AS_DLL
for the reason luaconf.h:
/*@@ LUA_API is a mark for all core API functions.@@ LUALIB_API is a mark for all auxiliary library functions.@@ LUAMOD_API is a mark for all standard library opening functions.** CHANGE them if you need to define those functions in some special way.** For instance, if you want to create one Windows DLL with the core and** the libraries, you may want to use the following definition (define** LUA_BUILD_AS_DLL to get it).*/#if defined(LUA_BUILD_AS_DLL) /* { */#if defined(LUA_CORE) || defined(LUA_LIB) /* { */#define LUA_API __declspec(dllexport)#else /* }{ */#define LUA_API __declspec(dllimport)#endif /* } */#else /* }{ */#define LUA_API extern#endif /* } */
LUAC53 cannot be compiled in the form of a dynamic-link library, because some core functions are not exported.
Project link in this article
Lua53 VS2015 Project
Please replace the absolute path in the project with your own path
Reference links
A simple example of writing a C module for Lua5.3