How to configure the MinGW Lua Environment

Source: Internet
Author: User

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:

 
 
  1. MINGW_PATH = "MinGW's main directory"
  2.  
  3. C_INCLUDE_PATH = "% MINGW_PATH % \ include; % MINGW_PATH % \ lib \ gcc \ mingw32 \ 3.4.5 \ include ";
  4.  
  5. CPLUS_INCLUDE_PATH = "% MINGW_PATH % \ include \ c ++ \ 3.4.5; % MINGW_PATH % \ include \ c ++ \ 3.4.5 \ mingw32; % MINGW_PATH %
  6.  
  7. \ Include \ c ++ \ 3.4.5 \ backward; % C_INCLUDE_PATH % ";
  8.  
  9. LIBRARY_PATH = "% MINGW_PATH % \ lib; % MINGW_PATH % \ lib \ gcc \ mingw32 \ 3.4.5 ";
  10.  
  11. 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.

 
 
  1. Function GetCurrPath ()
  2. {
  3. Fso = new ActiveXObject ("Scripting. FileSystemObject ");
  4. CurrFolder = fso. GetFolder (".");
  5. Return currFolder. path
  6. }
  7.  
  8. // Obtain the current path
  9. MINGW_PATH = GetCurrPath ();
  10.  
  11. C_INCLUDE_PATH = "% MINGW_PATH % \ include; % MINGW_PATH % \ lib \ gcc \ mingw32 \ 3.4.5 \ include ";
  12.  
  13. CPLUS_INCLUDE_PATH = "% MINGW_PATH % \ include \ c ++ \ 3.4.5; % MINGW_PATH % \ include \ c ++ \ 3.4.5 \ mingw32; % MINGW_PATH % \ include \
  14.  
  15. \ C ++ \ 3.4.5 \ backward; % C_INCLUDE_PATH % ";
  16.  
  17. LIBRARY_PATH = "% MINGW_PATH % \ lib; % MINGW_PATH % \ lib \ gcc \ mingw32 \ 3.4.5 ";
  18.  
  19. PATH = "% MINGW_PATH % \ bin; % MINGW_PATH % \ libexec \ gcc \ mingw32 \ 3.4.5 ;";
  20.  
  21. Var WshShell = WScript. CreateObject ("WScript. Shell ");
  22. Var WshSysEnv = WshShell. Environment ("SYSTEM ");
  23. WshSysEnv ("MINGW_PATH") = MINGW_PATH;
  24. WshSysEnv ("C_INCLUDE_PATH") = C_INCLUDE_PATH;
  25. WshSysEnv ("CPLUS_INCLUDE_PATH") = CPLUS_INCLUDE_PATH;
  26. WshSysEnv ("LIBRARY_PATH") = LIBRARY_PATH;
  27. PATHPATH = PATH + WshSysEnv ("PATH ");
  28. WshSysEnv ("PATH") = PATH;
  29. WScript. Echo ("MinGW environment variable setting is complete! ");

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

 
 
  1. Lua  
  2. │  
  3. ├─bin  
  4. │      bin2c.exe  
  5. │      lua.exe  
  6. │      lua5.1.dll  
  7. │      lua51.dll  
  8. │      luac.exe  
  9. │      wlua.exe  
  10. │  
  11. ├─include  
  12. │      lauxlib.h  
  13. │      lua.h  
  14. │      lua.hpp  
  15. │      luaconf.h  
  16. │      lualib.h  
  17. │  
  18. └─lib  
  19.         lua5.1.lib  
  20.         lua51.lib 

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

 
 
  1. Function GetCurrPath ()
  2. {
  3. Fso = new ActiveXObject ("Scripting. FileSystemObject ");
  4. CurrFolder = fso. GetFolder (".");
  5. Return currFolder. path
  6. }
  7.  
  8. // Obtain the current path
  9. LUA_HOME = GetCurrPath ();
  10.  
  11. LUA_BIN = "% LUA_HOME % \ bin ;";
  12.  
  13. LUA_INCLUDE = "% LUA_HOME % \ include ;";
  14.  
  15. LUA_LIB = "% LUA_HOME % \ lib ;";
  16.  
  17. Var WshShell = WScript. CreateObject ("WScript. Shell ");
  18. Var WshSysEnv = WshShell. Environment ("SYSTEM ");
  19.  
  20. WshSysEnv ("LUA_HOME") = LUA_HOME;
  21. // Add the path to the bin
  22. WshSysEnv ("PATH") = LUA_BIN + WshSysEnv ("PATH ");
  23. // Add include to MinGW
  24. WshSysEnv ("C_INCLUDE_PATH") = LUA_INCLUDE + WshSysEnv ("C_INCLUDE_PATH ");
  25. // Add lib to MinGW
  26. WshSysEnv ("LIBRARY_PATH") = LUA_LIB + WshSysEnv ("LIBRARY_PATH ");
  27. WScript. Echo ("LUA environment variable setting is complete! ");
  28.  
  29. Sometimes the setting does not take effect. Just restart it. First write a Hello World test.
  30.  
  31. # Include <lua. hpp>
  32. # Include <iostream>
  33. Using namespace std;
  34. Int main ()
  35. {
  36. Lua_State * L = lua_open ();
  37. Lua_cpcall (L, luaopen_base, 0 );
  38.  
  39. If (luaL_loadfile (L, "test. lua") | lua_pcall (L, 0, 0, 0 ))
  40. Cout <lua_tostring (L,-1) <endl;
  41. Lua_close (L );
  42. System ("pause ");
  43. Return 0;
  44. }
  45. Test. lua:
  46. Print ("Hello World! ")
  47. Makefile:
  48. All: main.exe
  49. # All: rebuild
  50. Main.exe
  51. Main.exe: main. o
  52. G ++-o $ @ $^-llua5.1
  53. Main. o: main. cpp
  54. G ++-c main. cpp
  55. Clear:
  56. -Del *. exe *. o
  57. Rebuild: clear main.exe

Make directly, compile, connect, and run once.

 
 
  1. g++ -c main.cpp  
  2. g++ -o main.exe main.o -llua5.1  
  3. main.exe  
  4. Hello World! 

Press any key to continue.

Summary: AboutMinGW Lua environment ConfigurationThe course content has been introduced. I hope this article will help you!

Related Article

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.