Compile Lua in VS2019 from sources - OnlineCop/kq-fork GitHub Wiki
Environment
- I am running Windows 10 Professional.
Note: This creates a single solution containing three distinct projects. These steps differ from this YouTube video, as the video instructs the viewer to change the project 3 different times, generating different output on each compile. The steps below allow you to generate all files from the same solution.
-
Open Visual Studio.
-
Under "Create a new project" search for "Blank Solution".
- It's under "All languages, All platforms, Other" or you can search for it within the templates.
- I named my solution
Luaand saved it in the defaultC:\Users\kqlives\source\reposdirectory.
-
You will create 3 separate projects: one for the library (
lua.dllandlua.lib), one for the Lua compiler (luac.exe), and one for the interpreter (lua.exe). You'll do these steps once for each of the projects:- Add an Empty Project for C++.
- It's under "C++, Windows, Console" or you can search for "Empty Project [C++]".
- Name the project.
- I named the first project
library, the second projectcompilerand the third projectinterpreter. - By default, the generated binaries use the name of the project, but we'll change those in the steps below.
- I named the first project
- Add an Empty Project for C++.
-
Change the solution's target from "Debug, x86" to "Release, x64".
- I've noticed that you can't change this until after there is at least one project created.
-
Change the Project Dependencies so
interpreterdepends onlibrary.- This ensures that
lua.libis available forinterpreterto link to.
- This ensures that
-
For the
libraryproject:- Add all .c source files to "Source Files", excluding
lua.candluac.c. - Modify the Project's [Configuration Properties]:
- [General] [Target Name]:
lua. - [General] [Configuration Type]:
Dynamic Library (.dll). - [C/C++] [General] [Additional Include Directories]: Lua source directory.
- Alternately, you can just add all .h source files to "Header Files".
- [C/C++] [Preprocessor] [Preprocessor Definitions]: Add
LUA_BUILD_AS_DLL.
- [General] [Target Name]:
- Add all .c source files to "Source Files", excluding
-
For the
compilerproject:- Add all .c source files to "Source Files", excluding
lua.c. - Modify the Project's [Configuration Properties]:
- [General] [Target Name]:
luac. - [General] [Configuration Type]:
Application (.exe). - [C/C++] [General] [Additional Include Directories]: Lua source directory.
- Alternately, you can just add all .h source files to "Header Files".
- [General] [Target Name]:
- Add all .c source files to "Source Files", excluding
-
For the
interpreterproject:- Add only
lua.cto "Source Files". - Modify the Project's [Configuration Properties]:
- [General] [Target Name]:
lua. - [General] [Configuration Type]:
Application (.exe). - [C/C++] [General] [Additional Include Directories]: Lua source directory.
- Alternately, you can just add all .h source files to "Header Files".
- [Linker] [General] [Additional Library Directories]:
$(OutDir). - [Linker] [Input] [Additional Dependencies]:
lua.lib.
- [General] [Target Name]:
- Add only
-
Build the solution.
- This should give you two library files (
lua.dll,lua.lib) and two binaries (luac.exe,lua.exe). - Mine were located under
Lua\Release.
- This should give you two library files (
-
Create a permanent location somewhere for the above files as well as for the Lua header files extracted earlier.
- You will need an
includedirectory within this permanent location, where you will copy all the Lua .h files into. - The YouTube video from above put the binaries and
includedirectory underC:\Program Files\Lua.
- You will need an