static link luasocket into lua with VC2010 under windows


1, download lua source code from luabinary project (it includes VC2008 project file). Unzip it to one folder.

2, download luasocket latest code. Unzip it to the folder we create in step1.

3, open lua solution file with vc2010 (I think VC2008 should be OK too). try to build it. Should be successful.

4, add all *.h *.c file of luasocket into the project. Remove following from project: usocket.h usocket.c unix.h unix.c. They are used by unix OS.

5, Modify the project setting.

preprocessor definitions look like: WIN32;_WIN32LUASOCKET_EXPORTS;LUASOCKET_DEBUG;LUASOCKET_API=__declspec(dllexport);NDEBUG;_CONSOLE;%(PreprocessorDefinitions)

and add “Ws2_32.lib;”into library.

6, insert

  {"mime", luaopen_mime_core},
  {"socket", luaopen_socket_core},

into luaL_Reg lualibs[] of linit.c file.

add two extern function declaration.

int luaopen_mime_core (lua_State *L);
int luaopen_socket_core (lua_State *L);

7, build.

8, change socket.lua under luasocket from require("socket.core") to require("socket") , change mime.lua, from require("mime.core") to require("mime")

9, in your test script, for example the testclnt.lua in luasocket/example, add this line

loadfile("socket.lua")()

before socket = require("socket");

10, run the test. Everything should be OK now.

http://comments.gmane.org/gmane.comp.lang.lua.general/67646

 

 


发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注