Summary of mingw + Lua environment configuration.

Source: Internet
Author: User

Although VC is the preferred tool for C ++ development in windows, sometimes I prefer to use some lightweight development tools to write some small programs. For example, I recently studied how to embed Lua into C ++. Sometimes I only write some small programs. At this time, Visual Studio seems too bloated. So I chose the editplus + mingw method. After two nights, we finally set up the environment. Here we will summarize it for future reference.
Mingw installation is relatively simple. I am lazy and directly launch an automatic installation program. He will download the latest package and decompress it to the correct location. To make it easier to use, you also need to configure the environment variables. There are still a lot of variables for Google. If this configuration is required on every machine, it is not very tiring. I decided to write a JS script to configure environment variables based on the principle that computers can do nothing. The method of modifying the registry was adopted at first, but later it was found that the method of modifying environment variables could not take effect immediately. Again, Google switched to the shell object of wscript to directly modify the environment variable.

 

Environment variables to be configured:

Mingw_path = "mingw's main directory"

C_include_path = "% mingw_path %/include; % mingw_path % // lib // GCC // mingw32 // 3.4.5 // include ";

Cplus_include_path = "% mingw_path %/include/C ++ // 3.4.5; % mingw_path % // include/C ++ // 3.4.5 // mingw32; % mingw_path %

// Include // C ++ // 3.4.5 // backward; % c_include_path % ";

LIBRARY_PATH = "% mingw_path % // LIB; % mingw_path % // lib // GCC // mingw32 // 3.4.5 ";

Path = "% mingw_path % // bin; % mingw_path % // libexec // GCC // mingw32 // 3.4.5 ;";

Write the JS script and put it in the mingw home directory. Double-click the script to run it.

Function
Getcurrpath ()
{
FSO =
New activexobject ("scripting. FileSystemObject ");
Currfolder =
FSO.
Getfolder (".");
Return
Currfolder.
Path
}

// Obtain the current path
Mingw_path =
Getcurrpath ();

C_include_path =
"% Mingw_path % // include; % mingw_path % // lib // GCC // mingw32 // 3.4.5 // include ";

Cplus_include_path
= "% Mingw_path % // include // C ++ // 3.4.5; % mingw_path % // include // C ++ // 3.4.5 // mingw32; % mingw_path % // include/

/C ++ // 3.4.5 // backward; % c_include_path % ";

LIBRARY_PATH =
"% Mingw_path % // LIB; % mingw_path % // lib // GCC // mingw32 // 3.4.5 ";

Path =
"% Mingw_path % // bin; % mingw_path % // libexec // GCC // mingw32 // 3.4.5 ;";

VaR
Wshshell =
Wscript. Createobject ("wscript. Shell ");
VaR
Wshsysenv =
Wshshell.
Environment ("system ");
Wshsysenv ("mingw_path ")
= Mingw_path;
Wshsysenv ("c_include_path ")
= C_include_path;
Wshsysenv ("cplus_include_path ")
= Cplus_include_path;
Wshsysenv ("LIBRARY_PATH ")
= LIBRARY_PATH;
Path =
Path + wshsysenv ("path ");
Wshsysenv ("path ")
= Path;
Wscript.
Echo ("mingw environment variable setting is complete! ");

 

In the Lua environment, download bin and Lib of Lua and make the following directory structure:

Lua

Zhu── Bin
│ Bin2c.exe
│ Lua.exe
│ Lua5.1.dll
│ Lua51.dll
│ Luac.exe
│ Wlua.exe

├ ── Include
│ Lauxlib. h
│ Lua. h
│ Lua. HPP
│ Luaconf. h
│ Lualib. h

└ ── Lib
Lua5.1.lib
Lua51.lib

 

Then the JS script is used to configure the environment variables:

Function
Getcurrpath ()
{
FSO =
New activexobject ("scripting. FileSystemObject ");
Currfolder =
FSO.
Getfolder (".");
Return
Currfolder.
Path
}

// Obtain the current path
Lua_home =
Getcurrpath ();

Lua_bin =
"% Lua_home % // bin ;";

Lua_include =
"% Lua_home % // include ;";

Lua_lib =
"% Lua_home % // LIB ;";

VaR
Wshshell =
Wscript. Createobject ("wscript. Shell ");
VaR
Wshsysenv =
Wshshell.
Environment ("system ");

Wshsysenv ("lua_home ")
= Lua_home;
// Add the path to the bin
Wshsysenv ("path ")
= Lua_bin
+ Wshsysenv ("path ");
// Add include to mingw
Wshsysenv ("c_include_path ")
= Lua_include
+ Wshsysenv ("c_include_path ");
// Add lib to mingw
Wshsysenv ("LIBRARY_PATH ")
= Lua_lib
+ Wshsysenv ("LIBRARY_PATH ");
Wscript.
Echo ("Lua environment variable setting is complete! ");

Sometimes the setting does not take effect. Just restart it. First write a hello World test.

# Include <Lua. HPP>
# Include <iostream>
Using
Namespace STD;

Int
Main ()
{
Lua_state *
L =
Lua_open ();
Lua_cpcall (L
, Luaopen_base
, 0 );

If (lual_loadfile (L
, "Test. Lua") |
Lua_pcall (L
, 0
, 0,
0 ))
Cout <
Lua_tostring (L
,-
1) <Endl;

Lua_close (L );

System ("pause ");
Return
0;
}

Test. Lua:

Print ("
Hello world! ")

Makefile:

ALL:
Main.exe
# All: Rebuild
Main.exe

Main.exe:
Main. o
G ++-o $ @
$^-Llua5.1

Main. O:
Main. cpp
G ++-C main. cpp

Clear:
-Del *. EXE *. o

Rebuild:
Clear main.exe

Make directly, compile, connect, and run once.

G ++-C main. cpp
G ++-O main.exe main. O-llua5.1
Main.exe
Hello world!
Press any key to continue...

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.