소스를 받아서 풀고 
http://w3.impa.br/~diego/software/luasocket/home.html#download

# make
cd src; make all
make[1]: Entering directory `/usr/local/src/luasocket-2.0.2/src'
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o luasocket.o luasocket.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o timeout.o timeout.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o buffer.o buffer.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o io.o io.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o auxiliar.o auxiliar.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o options.o options.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o inet.o inet.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o tcp.o tcp.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o udp.o udp.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o except.o except.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o select.o select.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o usocket.o usocket.c
gcc  -O -shared -fpic -o socket.so.2.0.2 luasocket.o timeout.o buffer.o io.o auxiliar.o options.o inet.o tcp.o udp.o except.o select.o usocket.o
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o mime.o mime.c
gcc  -O -shared -fpic -o mime.so.1.0.2 mime.o
make[1]: Leaving directory `/usr/local/src/luasocket-2.0.2/src'


# make install
cd src; make all
make[1]: Entering directory `/usr/local/src/luasocket-2.0.2/src'
make[1]: `all'를 위해 할 일이 없습니다
make[1]: Leaving directory `/usr/local/src/luasocket-2.0.2/src'
cd src; mkdir -p /usr/local/share/lua/5.1
cd src; cp ltn12.lua socket.lua mime.lua /usr/local/share/lua/5.1
cd src; mkdir -p /usr/local/share/lua/5.1/socket
cd src; cp http.lua url.lua tp.lua ftp.lua smtp.lua /usr/local/share/lua/5.1/socket
cd src; mkdir -p /usr/local/lib/lua/5.1/socket
cd src; cp socket.so.2.0.2  /usr/local/lib/lua/5.1/socket/core.so
#cd src; mkdir -p /usr/local/share/lua/5.1/mime
#cd src; cp  /usr/local/share/lua/5.1/mime
cd src; mkdir -p /usr/local/lib/lua/5.1/mime
cd src; cp mime.so.1.0.2 /usr/local/lib/lua/5.1/mime/core.so


# lua
Lua 5.1.2  Copyright (C) 1994-2007 Lua.org, PUC-Rio
> require('socket')
stdin:1: module 'socket' not found:
        no field package.preload['socket']
        no file './socket.lua'
        no file '/usr/share/lua/5.1/socket.lua'
        no file '/usr/share/lua/5.1/socket/init.lua'
        no file '/usr/lib/lua/5.1/socket.lua'
        no file '/usr/lib/lua/5.1/socket/init.lua'
        no file './socket.so'
        no file '/usr/lib/lua/5.1/socket.so'
        no file '/usr/lib/lua/5.1/loadall.so'
stack traceback:
        [C]: in function 'require'
        stdin:1: in main chunk
        [C]: ?
socket 모듈을 찾지 못합니다.

# ln -s /usr/local/share/lua /usr/share/lua
# export LUA_CPATH=/usr/local//lib/lua/5.1/socket/core.so
심볼릭 링크로 연결해 주고,
LUA_CPATH 를 연결

# lua
Lua 5.1.2  Copyright (C) 1994-2007 Lua.org, PUC-Rio
> require('socket')
>


동작합니다.

2010-12-07 추가 내용
>  require('socket')
error loading module 'socket' from file '/usr/local//lib/lua/5.1/socket/core.so':
        /usr/local//lib/lua/5.1/socket/core.so: undefined symbol: luaopen_socket
stack traceback:
        [C]: ?
        [C]: in function 'require'
        stdin:1: in main chunk
        [C]: ?
>
위와 같은 에러가 발생할 경우

소스에서 2개의 파일을 수정해서 해결했습니다.
luasocket.c
수정 전
LUASOCKET_API int luaopen_socket_core(lua_State *L) { 
수정 후
LUASOCKET_API int luaopen_socket(lua_State *L) {

luasocket.h
수정 전
LUASOCKET_API int luaopen_socket_core(lua_State *L);
수정 후
LUASOCKET_API int luaopen_socket(lua_State *L);
* LUA_CPATH 를 이용해서 라이브러리를 잡아주는 것이 좋습니다.

참고1)
LUA_CPATH 환경변수를 셋팅하지 않고 lua 를 실행 후에 package.cpath 를 셋팅할 수도 있습니다.
package.cpath="/usr/local//lib/lua/5.1/socket/core.so"


참고2) 사용환경입니다.
# cat /etc/issue
Fedora release 8 (Werewolf)

# rpm -q lua
lua-5.1.2-1.fc8

# rpm -ql lua
/usr/bin/lua
/usr/bin/luac
/usr/lib/liblua-5.1.so
/usr/share/doc/lua-5.1.2
/usr/share/doc/lua-5.1.2/COPYRIGHT
/usr/share/doc/lua-5.1.2/HISTORY
/usr/share/doc/lua-5.1.2/README
/usr/share/doc/lua-5.1.2/amazon.gif
/usr/share/doc/lua-5.1.2/contents.html
/usr/share/doc/lua-5.1.2/cover.png
/usr/share/doc/lua-5.1.2/logo.gif
/usr/share/doc/lua-5.1.2/lua.css
/usr/share/doc/lua-5.1.2/lua.html
/usr/share/doc/lua-5.1.2/luac.html
/usr/share/doc/lua-5.1.2/manual.css
/usr/share/doc/lua-5.1.2/manual.html
/usr/share/doc/lua-5.1.2/readme.html
/usr/share/man/man1/lua.1.gz
/usr/share/man/man1/luac.1.gz

참고3) buffer_init 함수 이슈.
buffer_init 함수명 때문에 lighttpd 의 mod_magnet 과  함께 사용할 때 문제가 생긴다.

That is obviously not a lighttpd bug. In fact memcache.lua uses luasockets. Luasockets has a buffer_init function that is called when sending data. Unfortunatly lighty also has a buffer_init method which overwrites luasocket's buffer_int method. Therefore the buffer get's not initialized correct and when the process tries to access buf->tm it fails with a null pointer (sigsegv).

In my opinion that is not a lighttpd bug, but in fact is a result of bad naming in luasockets as a library should at least prefix it's exported methods.

buffer_init 함수명을 임의로 변경하여 해결.

'programming' 카테고리의 다른 글

lua library 설치  (0) 2010.12.07
c2ps - C/C++ to Postscript Converter  (0) 2010.12.07
맨날 헷갈리는 Makefile 패턴규칙 꼬릿말규칙  (0) 2010.08.18
printf 에서 % 기호 표시  (0) 2010.08.02
java - jar , javap  (0) 2010.07.16
Latest update: 2010. 10. 7. 10:50