由于需要获得本机的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
 cd src; make all
make[1]: Entering directory `/data/tools/luasocket-2.0.2/src'
gcc -I/opt/soft/openresty/luajit/include/luajit-2.1/ -DLUASOCKET_DEBUG -pedantic -Wall -O2 -fpic -c -o luasocket.o luasocket.c
In file included from luasocket.c:31:0:
auxiliar.h:38:61: error: unknown type name ‘luaL_reg’
void auxiliar_newclass(lua_State *L, const char *classname, luaL_reg *func);
^
luasocket.c:50:1: error: unknown type name ‘luaL_reg’
static const luaL_reg mod[] = {
^
luasocket.c:51:5: warning: braces around scalar initializer [enabled by default]
{"auxiliar", auxiliar_open},
^
luasocket.c:51:5: warning: (near initialization for ‘mod[0]’) [enabled by default]
luasocket.c:51:5: warning: initialization makes integer from pointer without a cast [enabled by default]
luasocket.c:51:5: warning: (near initialization for ‘mod[0]’) [enabled by default]
luasocket.c:51:5: error: initializer element is not computable at load time
luasocket.c:51:5: error: (near initialization for ‘mod[0]’)
luasocket.c:51:5: warning: excess elements in scalar initializer [enabled by default]
luasocket.c:51:5: warning: (near initialization for ‘mod[0]’) [enabled by default]
luasocket.c:52:5: warning: braces around scalar initializer [enabled by default]
{"except", except_open},
^
luasocket.c:52:5: warning: (near initialization for ‘mod[1]’) [enabled by default]
luasocket.c:52:5: warning: initialization makes integer from pointer without a cast [enabled by default]
luasocket.c:52:5: warning: (near initialization for ‘mod[1]’) [enabled by default]
luasocket.c:52:5: error: initializer element is not computable at load time
luasocket.c:52:5: error: (near initialization for ‘mod[1]’)
luasocket.c:52:5: warning: excess elements in scalar initializer [enabled by default]
luasocket.c:52:5: warning: (near initialization for ‘mod[1]’) [enabled by default]
luasocket.c:53:5: warning: braces around scalar initializer [enabled by default]
{"timeout", timeout_open},
^
luasocket.c:53:5: warning: (near initialization for ‘mod[2]’) [enabled by default]
luasocket.c:53:5: warning: initialization makes integer from pointer without a cast [enabled by default]
luasocket.c:53:5: warning: (near initialization for ‘mod[2]’) [enabled by default]
luasocket.c:53:5: error: initializer element is not computable at load time
luasocket.c:53:5: error: (near initialization for ‘mod[2]’)
luasocket.c:53:5: warning: excess elements in scalar initializer [enabled by default]
luasocket.c:53:5: warning: (near initialization for ‘mod[2]’) [enabled by default]
luasocket.c:54:5: warning: braces around scalar initializer [enabled by default]
{"buffer", buffer_open},
^
luasocket.c:54:5: warning: (near initialization for ‘mod[3]’) [enabled by default]
luasocket.c:54:5: warning: initialization makes integer from pointer without a cast [enabled by default]
luasocket.c:54:5: warning: (near initialization for ‘mod[3]’) [enabled by default]
luasocket.c:54:5: error: initializer element is not computable at load time
luasocket.c:54:5: error: (near initialization for ‘mod[3]’)
luasocket.c:54:5: warning: excess elements in scalar initializer [enabled by default]
luasocket.c:54:5: warning: (near initialization for ‘mod[3]’) [enabled by default]
luasocket.c:55:5: warning: braces around scalar initializer [enabled by default]
{"inet", inet_open},
^
luasocket.c:55:5: warning: (near initialization for ‘mod[4]’) [enabled by default]
luasocket.c:55:5: warning: initialization makes integer from pointer without a cast [enabled by default]
luasocket.c:55:5: warning: (near initialization for ‘mod[4]’) [enabled by default]
luasocket.c:55:5: error: initializer element is not computable at load time
luasocket.c:55:5: error: (near initialization for ‘mod[4]’)
luasocket.c:55:5: warning: excess elements in scalar initializer [enabled by default]
luasocket.c:55:5: warning: (near initialization for ‘mod[4]’) [enabled by default]
luasocket.c:56:5: warning: braces around scalar initializer [enabled by default]
{"tcp", tcp_open},
^
luasocket.c:56:5: warning: (near initialization for ‘mod[5]’) [enabled by default]
luasocket.c:56:5: warning: initialization makes integer from pointer without a cast [enabled by default]
luasocket.c:56:5: warning: (near initialization for ‘mod[5]’) [enabled by default]
luasocket.c:56:5: error: initializer element is not computable at load time
luasocket.c:56:5: error: (near initialization for ‘mod[5]’)
luasocket.c:56:5: warning: excess elements in scalar initializer [enabled by default]
luasocket.c:56:5: warning: (near initialization for ‘mod[5]’) [enabled by default]
luasocket.c:57:5: warning: braces around scalar initializer [enabled by default]
{"udp", udp_open},
^
luasocket.c:57:5: warning: (near initialization for ‘mod[6]’) [enabled by default]
luasocket.c:57:5: warning: initialization makes integer from pointer without a cast [enabled by default]
luasocket.c:57:5: warning: (near initialization for ‘mod[6]’) [enabled by default]
luasocket.c:57:5: error: initializer element is not computable at load time
luasocket.c:57:5: error: (near initialization for ‘mod[6]’)
luasocket.c:57:5: warning: excess elements in scalar initializer [enabled by default]
luasocket.c:57:5: warning: (near initialization for ‘mod[6]’) [enabled by default]
luasocket.c:58:5: warning: braces around scalar initializer [enabled by default]
{"select", select_open},
^
luasocket.c:58:5: warning: (near initialization for ‘mod[7]’) [enabled by default]
luasocket.c:58:5: warning: initialization makes integer from pointer without a cast [enabled by default]
luasocket.c:58:5: warning: (near initialization for ‘mod[7]’) [enabled by default]
luasocket.c:58:5: error: initializer element is not computable at load time
luasocket.c:58:5: error: (near initialization for ‘mod[7]’)
luasocket.c:58:5: warning: excess elements in scalar initializer [enabled by default]
luasocket.c:58:5: warning: (near initialization for ‘mod[7]’) [enabled by default]
luasocket.c:59:5: warning: braces around scalar initializer [enabled by default]
{NULL, NULL}
^
luasocket.c:59:5: warning: (near initialization for ‘mod[8]’) [enabled by default]
luasocket.c:59:5: warning: initialization makes integer from pointer without a cast [enabled by default]
luasocket.c:59:5: warning: (near initialization for ‘mod[8]’) [enabled by default]
luasocket.c:59:5: warning: excess elements in scalar initializer [enabled by default]
luasocket.c:59:5: warning: (near initialization for ‘mod[8]’) [enabled by default]
luasocket.c:62:1: error: unknown type name ‘luaL_reg’
static luaL_reg func[] = {
^
luasocket.c:63:5: warning: braces around scalar initializer [enabled by default]
{"skip", global_skip},
^
luasocket.c:63:5: warning: (near initialization for ‘func[0]’) [enabled by default]
luasocket.c:63:5: warning: initialization makes integer from pointer without a cast [enabled by default]
luasocket.c:63:5: warning: (near initialization for ‘func[0]’) [enabled by default]
luasocket.c:63:5: error: initializer element is not computable at load time
luasocket.c:63:5: error: (near initialization for ‘func[0]’)
luasocket.c:63:5: warning: excess elements in scalar initializer [enabled by default]
luasocket.c:63:5: warning: (near initialization for ‘func[0]’) [enabled by default]
luasocket.c:64:5: warning: braces around scalar initializer [enabled by default]
{"__unload", global_unload},
^
luasocket.c:64:5: warning: (near initialization for ‘func[1]’) [enabled by default]
luasocket.c:64:5: warning: initialization makes integer from pointer without a cast [enabled by default]
luasocket.c:64:5: warning: (near initialization for ‘func[1]’) [enabled by default]
luasocket.c:64:5: error: initializer element is not computable at load time
luasocket.c:64:5: error: (near initialization for ‘func[1]’)
luasocket.c:64:5: warning: excess elements in scalar initializer [enabled by default]
luasocket.c:64:5: warning: (near initialization for ‘func[1]’) [enabled by default]
luasocket.c:65:5: warning: braces around scalar initializer [enabled by default]
{NULL, NULL}
^
luasocket.c:65:5: warning: (near initialization for ‘func[2]’) [enabled by default]
luasocket.c:65:5: warning: initialization makes integer from pointer without a cast [enabled by default]
luasocket.c:65:5: warning: (near initialization for ‘func[2]’) [enabled by default]
luasocket.c:65:5: warning: excess elements in scalar initializer [enabled by default]
luasocket.c:65:5: warning: (near initialization for ‘func[2]’) [enabled by default]
luasocket.c: In function ‘base_open’:
luasocket.c:92:9: warning: passing argument 3 of ‘luaL_openlib’ from incompatible pointer type [enabled by default]
luaL_openlib(L, "socket", func, 0);
^
In file included from luasocket.c:21:0:
/opt/soft/openresty/luajit/include/luajit-2.1/lauxlib.h:26:18: note: expected ‘const struct luaL_Reg *’ but argument is of type ‘int *’
LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,
^
luasocket.c: In function ‘luaopen_socket_core’:
luasocket.c:116:23: error: request for member ‘name’ in something not a structure or union
for (i = 0; mod[i].name; i++) mod[i].func(L);
^
luasocket.c:116:41: error: request for member ‘func’ in something not a structure or union
for (i = 0; mod[i].name; i++) mod[i].func(L);
^
luasocket.c:116:46: error: called object is not a function or function pointer
for (i = 0; mod[i].name; i++) mod[i].func(L);
^
luasocket.c:116:35: warning: statement with no effect [-Wunused-value]
for (i = 0; mod[i].name; i++) mod[i].func(L);
^
make[1]: *** [luasocket.o] Error 1
make[1]: Leaving directory `/data/tools/luasocket-2.0.2/src'
make: *** [all] Error 2

make时候报错

 root@fbprophet-10.153.169.67[17:29:32]$ grep -r -i luaL_reg /opt/soft/openresty/ |grep -v Binary
/opt/soft/openresty/resty.index: section 127415 127764 lual_reg
/opt/soft/openresty/resty.index: section 127764 128541 lual_register
/opt/soft/openresty/resty.index: section 195477 195545 function lual_openlib was replaced by lual_register.
/opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod:=head2 C<luaL_Reg>
/opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod: typedef struct luaL_Reg {
/opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod: } luaL_Reg;
/opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod:Type for arrays of functions to be registered by C<luaL_register>.
/opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod:Any array of C<luaL_Reg> must end with an sentinel entry in which both
/opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod:=head2 C<luaL_register>
/opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod: void luaL_register (lua_State *L,
/opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod: const luaL_Reg *l);
/opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod:functions in the list C<l> (see C<luaL_Reg>) into the table on the top
/opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod:When called with a non-null C<libname>, C<luaL_register> creates a new
/opt/soft/openresty/pod/lua-5.1.5/lua-5.1.5.pod:=item * Function C<luaL_openlib> was replaced by C<luaL_register>.
/opt/soft/openresty/luajit/include/luajit-2.1/lauxlib.h:typedef struct luaL_Reg {
/opt/soft/openresty/luajit/include/luajit-2.1/lauxlib.h:} luaL_Reg;
/opt/soft/openresty/luajit/include/luajit-2.1/lauxlib.h: const luaL_Reg *l, int nup);
/opt/soft/openresty/luajit/include/luajit-2.1/lauxlib.h:LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
/opt/soft/openresty/luajit/include/luajit-2.1/lauxlib.h: const luaL_Reg *l);
/opt/soft/openresty/luajit/include/luajit-2.1/lauxlib.h:LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
root@fbprophet-10.153.169.67[17:29:36]$

查找luaL_reg

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

 typedef struct luaL_Reg {
const char *name;
lua_CFunction func;
} luaL_Reg;

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

然后重新编译就可以了。

luasocket编译安装遇到的坑的更多相关文章

  1. openssl1.0在mac下的编译安装(踩坑精华)

    之前做了一次brew版本升级,然后用pip3安装的一个python命令就无法执行了(涉及到openssl库),执行就会报一个错误. ImportError: dlopen(/usr/local/Cel ...

  2. centos7编译安装redis遇坑

    编译redis时:make cc Command not found 原因分析:没有安装gcc,执行: yum install gcc 编译redis时:error: jemalloc/jemallo ...

  3. 源码编译安装 ganesha

    源码编译安装 ganesha 简介 系统环境:CentOS 7.5 ceph:luminous nfs-ganesha:v2.6 stable 安装步骤 安装依赖 首先需要安装编译会用到的公共库 1 ...

  4. Ubuntu16.04编译安装tensorflow,2018最新血泪踩坑之后的全面总结!绝对成功!【转】

    本文转载自:https://blog.csdn.net/pzh11001/article/details/79683133 大家好,我是 (深度学习硬件DIY总群)(719577294)群主:    ...

  5. mac M1 php扩展 xlswriter 编译安装爬坑记录

    电脑配置 MacBook Pro(14英寸,2021年) 系统版本 macOS Monterey 12.4 芯片 Apple M1 Pro PHP环境 MAMP Pro Version 6.6.1 ( ...

  6. 源码编译安装lnmp环境(nginx-1.14.2 + mysql-5.6.43 + php-5.6.30 )------踩了无数坑,重装了十几次服务器才会的,不容易啊!

    和LAMP不同的是,LNMP中的N指的是Nginx(类似于Apache的一种web服务软件),并且php是作为一个独立服务存在的,这个服务叫做php-fpm,Nginx直接处理静态请求,动态请求会转发 ...

  7. 源码编译安装MySQL-5.6/mysql-5.6.39------踩了无数坑,重装了十几次服务器才会的,不容易啊!

    1.切换到src目录 cd /usr/local/src/ 2. 下载mysql免编译二进制包 免编译的mysql二进制包5.6源码包: wget http://mirrors.163.com/mys ...

  8. 源码编译安装Apache/2.4.37-------踩了无数坑,重装了十几次服务器才会的,不容易啊!

    1.先进入/usr/local/中创建三个文件夹 apr apr-util apache cd /usr/local目录 mkdir apr mkdir apr-util mkdir apache 2 ...

  9. Opencv3.3(Linux)编译安装至python的坑

    编译安装OpenCV绝对是一件让人发狂的事情,CMake繁多的选项,国内蛋疼的网速,实在让人无力吐槽,然而为了使用contrib包,我不得不重新编译他. OpenCV的编译 其实OpenCV编译并不是 ...

随机推荐

  1. 自学MongoDB(1)

    MongoDB是nosql(非关系型数据库)中的一种,面向文档的数据库,介于传统的结构化数据库(关系型数据库)与非关系型数据库(文件储存)之间的一种,具有数据结构非常松散和非常灵活的特点;常用于存储分 ...

  2. js用canvans 实现简单的粒子运动

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  3. Failure sending mail: The user or group name 'xxx\xxxx' is not recognized.Mail will not be resent

      一批Reporting Service报表的订阅突然报如下错误: Failure sending mail: The user or group name 'xxx\xxxx' is not re ...

  4. xtrabackup备份mysql数据库方法

    1.安装 xtrabackup 工具包 下载percona yum源 https://www.percona.com/redir/downloads/percona-release/redhat/pe ...

  5. selenium之元素定位-xpath

    被测试网页的HTML代码 <html> <body> <div id="div1" style="text-align:center&quo ...

  6. Linux Mint如何添加windows分享的网络打印机?

    1.安装samba sudo apt-get install samba 2.找到系统打印机选项 通过 Menu-->>控制中心-->>系统管理找到 Printers选项,双击 ...

  7. MATLAB中“repmat”与“cat”函数的用法

    MATLAB中“repmat”与“cat”函数的用法 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 1. repmat函数 >> z=re ...

  8. 【spring源码分析】IOC容器初始化(四)

    前言:在[spring源码分析]IOC容器初始化(三)中已经分析了BeanDefinition注册之前的一些准备工作,下面将进入BeanDefinition注册的核心流程. //DefaultBean ...

  9. Linux云计算工程师

    一.Linux运维基础 二.Linux运维高级-核心知识提高 三.50台集群实战 四.200-1000台集群实战 五.shell编程企业级实战 六.数据库MySQL和NoSQL 七.LVM虚拟化和机房 ...

  10. golang web实战之二(iris)

    之前写了一篇为:golang web实战之一(beego,mvc postgresql) 听说iris更好: 1.  iris hello world package main import &quo ...