AboutMinGW Lua environment ConfigurationIs the content to be introduced in this article, mainly to learnLuaMediumEnvironment ConfigurationFor more information, see this article.
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, recent studiesLuaEmbedded in C ++, sometimes only write some small programs. At this time, Visual Studio is too bloated, so I chose EditPlus +MinGW. After two nights, we finally set up the environment. Here we will summarize it for future reference.
MinGWInstallation 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;
- PATHPATH = 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
- │
- ├─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.
Summary: AboutMinGW Lua environment ConfigurationThe course content has been introduced. I hope this article will help you!