luasocket编译安装遇到的坑

 

由于需要获得本机的IP地址,所以需要 :

local socket = require('socket')
local server_hostname = socket.dns.gethostname()
local server_ip = socket.dns.toip(server_hostname)

 

需要下载源码编译:luasocket-2.0.2.tar.gz

- 解压好之后首先修改config文件来制定安装的路径,修改涉及的三个地方:

# 由于是先安装的openresty-1.13.6.1:/opt/soft/openresty/
LUAINC=-I/opt/soft/openresty/luajit/include/luajit-2.1/
INSTALL_TOP_SHARE=/opt/soft/openresty/luajit/share/lua/5.1
INSTALL_TOP_LIB=/opt/soft/openresty/luajit/lib/lua/5.1

- 编译安装

make
make install 
  1 cd src; make all
  2 make[1]: Entering directory `/data/tools/luasocket-2.0.2/src'
  3 gcc -I/opt/soft/openresty/luajit/include/luajit-2.1/ -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o luasocket.o luasocket.c
  4 In file included from luasocket.c:31:0:
  5 auxiliar.h:38:61: error: unknown type name ‘luaL_reg’
  6  void auxiliar_newclass(lua_State *L, const char *classname, luaL_reg *func);
  7                                                              ^
  8 luasocket.c:50:1: error: unknown type name ‘luaL_reg’
  9  static const luaL_reg mod[] = {
 10  ^
 11 luasocket.c:51:5: warning: braces around scalar initializer [enabled by default]
 12      {"auxiliar", auxiliar_open},
 13      ^
 14 luasocket.c:51:5: warning: (near initialization for ‘mod[0]’) [enabled by default]
 15 luasocket.c:51:5: warning: initialization makes integer from pointer without a cast [enabled by default]
 16 luasocket.c:51:5: warning: (near initialization for ‘mod[0]’) [enabled by default]
 17 luasocket.c:51:5: error: initializer element is not computable at load time
 18 luasocket.c:51:5: error: (near initialization for ‘mod[0]’)
 19 luasocket.c:51:5: warning: excess elements in scalar initializer [enabled by default]
 20 luasocket.c:51:5: warning: (near initialization for ‘mod[0]’) [enabled by default]
 21 luasocket.c:52:5: warning: braces around scalar initializer [enabled by default]
 22      {"except", except_open},
 23      ^
 24 luasocket.c:52:5: warning: (near initialization for ‘mod[1]’) [enabled by default]
 25 luasocket.c:52:5: warning: initialization makes integer from pointer without a cast [enabled by default]
 26 luasocket.c:52:5: warning: (near initialization for ‘mod[1]’) [enabled by default]
 27 luasocket.c:52:5: error: initializer element is not computable at load time
 28 luasocket.c:52:5: error: (near initialization for ‘mod[1]’)
 29 luasocket.c:52:5: warning: excess elements in scalar initializer [enabled by default]
 30 luasocket.c:52:5: warning: (near initialization for ‘mod[1]’) [enabled by default]
 31 luasocket.c:53:5: warning: braces around scalar initializer [enabled by default]
 32      {"timeout", timeout_open},
 33      ^
 34 luasocket.c:53:5: warning: (near initialization for ‘mod[2]’) [enabled by default]
 35 luasocket.c:53:5: warning: initialization makes integer from pointer without a cast [enabled by default]
 36 luasocket.c:53:5: warning: (near initialization for ‘mod[2]’) [enabled by default]
 37 luasocket.c:53:5: error: initializer element is not computable at load time
 38 luasocket.c:53:5: error: (near initialization for ‘mod[2]’)
 39 luasocket.c:53:5: warning: excess elements in scalar initializer [enabled by default]
 40 luasocket.c:53:5: warning: (near initialization for ‘mod[2]’) [enabled by default]
 41 luasocket.c:54:5: warning: braces around scalar initializer [enabled by default]
 42      {"buffer", buffer_open},
 43      ^
 44 luasocket.c:54:5: warning: (near initialization for ‘mod[3]’) [enabled by default]
 45 luasocket.c:54:5: warning: initialization makes integer from pointer without a cast [enabled by default]
 46 luasocket.c:54:5: warning: (near initialization for ‘mod[3]’) [enabled by default]
 47 luasocket.c:54:5: error: initializer element is not computable at load time
 48 luasocket.c:54:5: error: (near initialization for ‘mod[3]’)
 49 luasocket.c:54:5: warning: excess elements in scalar initializer [enabled by default]
 50 luasocket.c:54:5: warning: (near initialization for ‘mod[3]’) [enabled by default]
 51 luasocket.c:55:5: warning: braces around scalar initializer [enabled by default]
 52      {"inet", inet_open},
 53      ^
 54 luasocket.c:55:5: warning: (near initialization for ‘mod[4]’) [enabled by default]
 55 luasocket.c:55:5: warning: initialization makes integer from pointer without a cast [enabled by default]
 56 luasocket.c:55:5: warning: (near initialization for ‘mod[4]’) [enabled by default]
 57 luasocket.c:55:5: error: initializer element is not computable at load time
 58 luasocket.c:55:5: error: (near initialization for ‘mod[4]’)
 59 luasocket.c:55:5: warning: excess elements in scalar initializer [enabled by default]
 60 luasocket.c:55:5: warning: (near initialization for ‘mod[4]’) [enabled by default]
 61 luasocket.c:56:5: warning: braces around scalar initializer [enabled by default]
 62      {"tcp", tcp_open},
 63      ^
 64 luasocket.c:56:5: warning: (near initialization for ‘mod[5]’) [enabled by default]
 65 luasocket.c:56:5: warning: initialization makes integer from pointer without a cast [enabled by default]
 66 luasocket.c:56:5: warning: (near initialization for ‘mod[5]’) [enabled by default]
 67 luasocket.c:56:5: error: initializer element is not computable at load time
 68 luasocket.c:56:5: error: (near initialization for ‘mod[5]’)
 69 luasocket.c:56:5: warning: excess elements in scalar initializer [enabled by default]
 70 luasocket.c:56:5: warning: (near initialization for ‘mod[5]’) [enabled by default]
 71 luasocket.c:57:5: warning: braces around scalar initializer [enabled by default]
 72      {"udp", udp_open},
 73      ^
 74 luasocket.c:57:5: warning: (near initialization for ‘mod[6]’) [enabled by default]
 75 luasocket.c:57:5: warning: initialization makes integer from pointer without a cast [enabled by default]
 76 luasocket.c:57:5: warning: (near initialization for ‘mod[6]’) [enabled by default]
 77 luasocket.c:57:5: error: initializer element is not computable at load time
 78 luasocket.c:57:5: error: (near initialization for ‘mod[6]’)
 79 luasocket.c:57:5: warning: excess elements in scalar initializer [enabled by default]
 80 luasocket.c:57:5: warning: (near initialization for ‘mod[6]’) [enabled by default]
 81 luasocket.c:58:5: warning: braces around scalar initializer [enabled by default]
 82      {"select", select_open},
 83      ^
 84 luasocket.c:58:5: warning: (near initialization for ‘mod[7]’) [enabled by default]
 85 luasocket.c:58:5: warning: initialization makes integer from pointer without a cast [enabled by default]
 86 luasocket.c:58:5: warning: (near initialization for ‘mod[7]’) [enabled by default]
 87 luasocket.c:58:5: error: initializer element is not computable at load time
 88 luasocket.c:58:5: error: (near initialization for ‘mod[7]’)
 89 luasocket.c:58:5: warning: excess elements in scalar initializer [enabled by default]
 90 luasocket.c:58:5: warning: (near initialization for ‘mod[7]’) [enabled by default]
 91 luasocket.c:59:5: warning: braces around scalar initializer [enabled by default]
 92      {NULL, NULL}
 93      ^
 94 luasocket.c:59:5: warning: (near initialization for ‘mod[8]’) [enabled by default]
 95 luasocket.c:59:5: warning: initialization makes integer from pointer without a cast [enabled by default]
 96 luasocket.c:59:5: warning: (near initialization for ‘mod[8]’) [enabled by default]
 97 luasocket.c:59:5: warning: excess elements in scalar initializer [enabled by default]
 98 luasocket.c:59:5: warning: (near initialization for ‘mod[8]’) [enabled by default]
 99 luasocket.c:62:1: error: unknown type name ‘luaL_reg’
100  static luaL_reg func[] = {
101  ^
102 luasocket.c:63:5: warning: braces around scalar initializer [enabled by default]
103      {"skip",      global_skip},
104      ^
105 luasocket.c:63:5: warning: (near initialization for ‘func[0]’) [enabled by default]
106 luasocket.c:63:5: warning: initialization makes integer from pointer without a cast [enabled by default]
107 luasocket.c:63:5: warning: (near initialization for ‘func[0]’) [enabled by default]
108 luasocket.c:63:5: error: initializer element is not computable at load time
109 luasocket.c:63:5: error: (near initialization for ‘func[0]’)
110 luasocket.c:63:5: warning: excess elements in scalar initializer [enabled by default]
111 luasocket.c:63:5: warning: (near initialization for ‘func[0]’) [enabled by default]
112 luasocket.c:64:5: warning: braces around scalar initializer [enabled by default]
113      {"__unload",  global_unload},
114      ^
115 luasocket.c:64:5: warning: (near initialization for ‘func[1]’) [enabled by default]
116 luasocket.c:64:5: warning: initialization makes integer from pointer without a cast [enabled by default]
117 luasocket.c:64:5: warning: (near initialization for ‘func[1]’) [enabled by default]
118 luasocket.c:64:5: error: initializer element is not computable at load time
119 luasocket.c:64:5: error: (near initialization for ‘func[1]’)
120 luasocket.c:64:5: warning: excess elements in scalar initializer [enabled by default]
121 luasocket.c:64:5: warning: (near initialization for ‘func[1]’) [enabled by default]
122 luasocket.c:65:5: warning: braces around scalar initializer [enabled by default]
123      {NULL,        NULL}
124      ^
125 luasocket.c:65:5: warning: (near initialization for ‘func[2]’) [enabled by default]
126 luasocket.c:65:5: warning: initialization makes integer from pointer without a cast [enabled by default]
127 luasocket.c:65:5: warning: (near initialization for ‘func[2]’) [enabled by default]
128 luasocket.c:65:5: warning: excess elements in scalar initializer [enabled by default]
129 luasocket.c:65:5: warning: (near initialization for ‘func[2]’) [enabled by default]
130 luasocket.c: In function ‘base_open’:
131 luasocket.c:92:9: warning: passing argument 3 of ‘luaL_openlib’ from incompatible pointer type [enabled by default]
132          luaL_openlib(L, "socket", func, 0);
133          ^
134 In file included from luasocket.c:21:0:
135 /opt/soft/openresty/luajit/include/luajit-2.1/lauxlib.h:26:18: note: expected ‘const struct luaL_Reg *’ but argument is of type ‘int *136  LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,
137                   ^
138 luasocket.c: In function ‘luaopen_socket_core’:
139 luasocket.c:116:23: error: request for member ‘name’ in something not a structure or union
140      for (i = 0; mod[i].name; i++) mod[i].func(L);
141                        ^
142 luasocket.c:116:41: error: request for member ‘func’ in something not a structure or union
143      for (i = 0; mod[i].name; i++) mod[i].func(L);
144                                          ^
145 luasocket.c:116:46: error: called object is not a function or function pointer
146      for (i = 0; mod[i].name; i++) mod[i].func(L);
147                                               ^
148 luasocket.c:116:35: warning: statement with no effect [-Wunused-value]
149      for (i = 0; mod[i].name; i++) mod[i].func(L);
150                                    ^
151 make[1]: *** [luasocket.o] Error 1
152 make[1]: Leaving directory `/data/tools/luasocket-2.0.2/src'
153 make: *** [all] Error 2
make时候报错

 

 1 [email protected][17:29:32]$ grep -r -i luaL_reg /opt/soft/openresty/ |grep -v Binary
 2 /opt/soft/openresty/resty.index:  section 127415 127764 lual_reg
 3 /opt/soft/openresty/resty.index:  section 127764 128541 lual_register
 4 /opt/soft/openresty/resty.index:  section 195477 195545 function lual_openlib was replaced by lual_register.
 5 /opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod:=head2 C
 6 /opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod: typedef struct luaL_Reg {
 7 /opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod: } luaL_Reg;
 8 /opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod:Type for arrays of functions to be registered by C.
 9 /opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod:Any array of C must end with an sentinel entry in which both
10 /opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod:=head2 C
11 /opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod: void luaL_register (lua_State *L,
12 /opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod:                     const luaL_Reg *l);
13 /opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod:functions in the list C (see C) into the table on the top
14 /opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod:When called with a non-null C, C creates a new
15 /opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod:=item * Function C was replaced by C.
16 /opt/soft/openresty/luajit/include/luajit-2.1/lauxlib.h:typedef struct luaL_Reg {
17 /opt/soft/openresty/luajit/include/luajit-2.1/lauxlib.h:} luaL_Reg;
18 /opt/soft/openresty/luajit/include/luajit-2.1/lauxlib.h:                                const luaL_Reg *l, int nup);
19 /opt/soft/openresty/luajit/include/luajit-2.1/lauxlib.h:LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
20 /opt/soft/openresty/luajit/include/luajit-2.1/lauxlib.h:                                const luaL_Reg *l);
21 /opt/soft/openresty/luajit/include/luajit-2.1/lauxlib.h:LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
22 [email protected][17:29:36]$ 
查找luaL_reg

  

/opt/soft/openresty/luajit/include/luajit-2.1/lauxlib.h 里定义的结构体名字和 luaL_reg 不一致

1 typedef struct luaL_Reg {
2   const char *name;
3   lua_CFunction func;
4 } luaL_Reg;

 

然后把 luasocket-2.0.2/src 下所有luaL_reg 替换成 luaL_Reg

然后重新编译就可以了。

 

转载于:https://www.cnblogs.com/standby/p/10737413.html

你可能感兴趣的:(luasocket编译安装遇到的坑)