How to use vs to build a C++/lua development environment on the Windows platform

Source: Internet
Author: User
Tags lua

Transferred from: http://ju.outofmemory.cn/entry/95358

This article focuses on how to use VS to build the C++/lua development environment on the Windows platform. The "C++/lua development environment" here mainly refers to C + + call Lua, and Lua calls C + +. Mac platforms are relatively convenient, but vs is not a hassle. The tutorial built on the Mac using Xcode can refer to Zilong's tutorial, but can also use other Ides, such as Eclipse+cdt+ldt to build, there is no problem.

In addition, this article does not talk about lua/c++ interaction, related content can refer to "LUA program design", or the Longshan of the Human LUA series tutorials.

Environment
    • Windows 8.1
    • VS2012
    • Lua5.2.3
How to Build

1. Generating a LUA static library

(1) Download Lua src.

The latest version is 5.2.3..

(2) New VS Win32 console application, named Lua. In the application settings, select the application type as static library, and in the additional option uncheck the precompiled header.

(3) Create a new LUASRC directory in the LUA vs project folder to store the LUA source code. Unzip the downloaded Lua src and copy all *. C and *. h files from the SRC directory to luasrc.

(4) Create a new bin directory in the LUA VS project folder for storing Lua.lib.

(5) In the VS environment, right-click on the LUA project, select Add-now, import all the files in the LUASRC directory.

(6) Right-click on the LUA project, select Properties, select All configurations at the top, and then modify the configuration properties, general-Output directory to

$(SolutionDir)bin

(7) In order to prohibit some security warnings (Windows programmers know why), you need to modify the configuration properties->c/c++–> preprocessor---preprocessor definition, add at the end

;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_DEPRECATE

(8) Select release mode, click on the project, generate Lua.lib. The Lua.lib is generated in the bin directory.

2. Calling the Lua Static library

(1) Create a new WIN32 console program named Hellolua under the LUA solution with default options and no modifications.

(2) Right click on Hellolua project, select Properties, modify configuration Properties->c/c++–> Additional include directory, add

..\LuaSrc

(3) Additional dependencies, input, linker, configuration Properties, change, new

..\bin\Lua.lib

Or use code to link the LUA library, i.e. add the following code to the HeloLua.cpp

#pragma comment (lib,"../bin/Lua.lib")

(4) Set Hellolua project as the default startup item, click Build Project.

(5) Because the main function does not execute any code at this point, the console flashes past. Right-Hellolua The project source file, add New item, name Hellolua.lua.

(6) A simple invocation example:

*hellolua.lua*Print ("Hello, Lua")*hellolua.cpp*#include"stdafx.h"  #pragmaComment (lib, "Lua.lib")#include"lua.hpp"  int_tmain (intARGC, _tchar*argv[]) {Lua_state* Lua_state =lual_newstate ();      Lual_openlibs (lua_state); Lual_dofile (Lua_state,"Hellolua.lua");      Lua_close (lua_state);      GetChar (); return 0; }

Effect

3. Generate Lua.exe and Luac.exe

Since the downloaded LUA source contains lua.c and LUAC.C, the two files have the main entry, and the compile error, so just delete one, the other can be compiled normally.

(1) New vs Empty Project, named Lua.

(2) Create a new LUASRC directory in the LUA vs project folder to store the LUA source code. Unzip the downloaded Lua src, copy the SRC directory is all *. C and *. h files.

(3) in the VS environment, right-click on the LUA project, select Add-now, import all the files in the LUASRC directory.

(4) Right click on the LUA project, select Properties, select All configurations at the top, then modify the configuration Properties->c/c++–> preprocessor---preprocessor definition, add at the end

;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_DEPRECATE

(5) in the LUA project source file, find luac.c, right-click Remove.

(6) Select release mode, click on the project to generate Lua.exe.

(7) Similarly create a LUAC empty project under the same solution, and generate Luac.exe as per the above steps. Just fifth step to "find LUA.C, right-click Remove".

(8) Lua.exe and Luac.exe generate the release directory under the LUA project directory.

C + + Invoke Lua project: https://github.com/fusijie/Cpp_Lua_VS2012

Lua and Luac project: Https://github.com/fusijie/Lua_LuaC_exe

If you don't want to be so troublesome, you can clone my project directly from the above 2 GitHub addresses.

Original address: http://www.fusijie.com/blog/2014/08/31/how-to-complie-cpp-with-lua-in-the-vs/
Copyright Disclaimer: Free Reprint-Non-commercial-non-derivative-retain attribution | Creative Commons by-nc-nd 3.0

How to use vs to build a C++/lua development environment on the Windows platform

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.