最近需要升级原有服务器的nginx加载逻辑,新的lua脚本需要解析一个远程返回的json格式的结果,原有的luajit并没有带cjson库,需要自己手动安装一下。

基本参考博客luajit安装cjson

cjson下载地址:http://www.kyne.com.au/~mark/software/lua-cjson.php

下载文件 lua-cjson-2.1.0.tar.gz

运行命令

tar -zxvf lua-cjson-2.1..tar.gz 

cd  lua-cjson-2.1.0

make

make命令在使用默认配置下报错

lua_cjson.c::: error: lua.h: No such file or directory
lua_cjson.c::: error: lauxlib.h: No such file or directory
lua_cjson.c:: error: expected ‘)’ before ‘*’ token
lua_cjson.c:: error: expected ‘)’ before ‘*’ token
lua_cjson.c:: error: expected ‘)’ before ‘*’ token
lua_cjson.c:: error: expected ‘)’ before ‘*’ token
lua_cjson.c:: error: expected ‘)’ before ‘*’ token
lua_cjson.c:: error: expected ‘)’ before ‘*’ token
lua_cjson.c:: error: expected ‘)’ before ‘*’ token
lua_cjson.c:: error: expected ‘)’ before ‘*’ token
lua_cjson.c:: error: expected ‘)’ before ‘*’ token
lua_cjson.c:: error: expected ‘)’ before ‘*’ token

根据上述博客和之前安装luasocket的经验,还是没有找到lua源码进行编译报的错。

find 一下lua.h这个文件,发现位于/opt/luajit-2.0.0/include/luajit-2.0路径下。

修改Makefile文件,修改default配置为

##                          multi-threaded application. Requries _pthreads_.

##### Build defaults #####
LUA_VERSION = 5.1
TARGET = cjson.so
PREFIX = /opt/luajit-2.0.
#CFLAGS = -g -Wall -pedantic -fno-inline
CFLAGS = -O3 -Wall -pedantic -DNDEBUG
CJSON_CFLAGS = -fpic
CJSON_LDFLAGS = -shared
#LUA_INCLUDE_DIR = $(PREFIX)/include
LUA_INCLUDE_DIR = /opt/luajit-2.0./include/luajit-2.0
LUA_CMODULE_DIR = $(PREFIX)/lib/lua/$(LUA_VERSION)
LUA_MODULE_DIR = $(PREFIX)/share/lua/$(LUA_VERSION)
LUA_BIN_DIR = $(PREFIX)/bin

主要是修改了LUA_INCLUDE_DIR用于安装cjson;修改了PREFIX变量用来改变编译结果文件输出的路径

保存修改,执行命令

make && make install
cc -c -O3 -Wall -pedantic -DNDEBUG -I/opt/luajit-2.0./include/luajit-2.0 -fpic -o lua_cjson.o lua_cjson.c
cc -c -O3 -Wall -pedantic -DNDEBUG -I/opt/luajit-2.0./include/luajit-2.0 -fpic -o strbuf.o strbuf.c
cc -c -O3 -Wall -pedantic -DNDEBUG -I/opt/luajit-2.0./include/luajit-2.0 -fpic -o fpconv.o fpconv.c
cc -shared -o cjson.so lua_cjson.o strbuf.o fpconv.o
mkdir -p //opt/luajit-2.0.0/lib/lua/5.1
cp cjson.so //opt/luajit-2.0.0/lib/lua/5.1
chmod //opt/luajit-2.0.0/lib/lua/5.1/cjson.so

输出结果显示正确,安装成功

luajit 安装cjson的更多相关文章

  1. 安装 luajit && 给 luajit 安装 cjson

    安装 luajit 步骤: 从官网 http://luajit.org/download.html下载  LuaJIT-2.0.5.tar.gz 解压 tar -xzf LuaJIT-2.0.5.ta ...

  2. nginx的luajit安装luarocks并安装luafilesystem

    nginx的luajit安装luarocks并安装luafilesystem by admin on -- :: in , 69次 标题有点绕口.我尽量把关键词都贴进去.之前因为自己的nginx安装了 ...

  3. lua 的 cjson 安装,使用

    1. 背景: 虚拟机安装的luajit  没有 cjson 库,就不能对 table 进行 编码操作,手动安装一个. 2. 安装: cjson下载地址:http://www.kyne.com.au/~ ...

  4. Redis进阶实践之八Lua的Cjson在Linux下安装、使用和用C#调用Lua脚本

    一.引言         学习Redis也有一段时间了,感触还是颇多的,但是自己很清楚,路还很长,还要继续.上一篇文章简要的介绍了如何在Linux环境下安装Lua,并介绍了在Linux环境下如何编写L ...

  5. 【LuaJIT版】从零开始在 macOS 上配置 Lua 开发环境

    前言 这篇文章针对的是基于 LuaJIT 的环境配置.借助于 LuaJIT,Lua 的执行效率可以进一步提升几十倍.如果你不是很清楚自己是需要 Lua 还是 LuaJIT,那么建议你从 LuaJIT ...

  6. 手动编译 Nginx 并安装 VeryNginx

    VeryNginx 是个非常有意思且便捷的 Nginx 扩展程序.最近新开了台 VPS,便想体验一下它带来的快感. VeryNginx 有个不超过 5 行的安装方法,但作为强迫症我更喜欢使用自己编译的 ...

  7. Nginx编译安装lua-nginx-module

    lua-nginx-module 模块可以将Lua的强大功能嵌入NGINX服务器. 下载Nginx源码 如果已安装Nginx,需要查看当前安装版本的编译参数: $ /usr/local/nginx/s ...

  8. LNMP平滑升级nginx并安装ngx_lua模块教程

    #ngx_lua module项目地址 https://github.com/chaoslawful/lua-nginx-module 在LNMP安装包后,重编译nginx,并添加ngx_lua模块 ...

  9. nginx+lua_module安装

    1.LuaJit安装 # cd /usr/local/src # git clone http://luajit.org/git/luajit-2.0.git # cd luajit-2.0 # ma ...

随机推荐

  1. Codevs 2549 自然数和分解

    2549 自然数和分解 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 白银 Silver 传送门 题目描述 Description 把自然数N分解为若干个自然数之和,输出方案数. 输 ...

  2. 要想重启后也生效LINUX防火墙配置

    新配置的一台服务器,安装的是CentOS6.3系统,在安装完LNMP之后,发现nginx进程存在,且php解析正常,但是用分配的独立IP去访问的时候发现无法访问. 查了下网上的资料,发现可能是Linu ...

  3. c++相关知识回顾

    1.typedef typedef用来定义同类型的同义词.如: typedef unsingned int size_t; typedef int ptrdiff_t; typedef T * ite ...

  4. C#winfrom中应用程序只启动一次代码

    static class Program    {        private const int WS_SHOWNORMAL = 1;        [DllImport("User32 ...

  5. input 标签的class 失效

    今天CSS网页的是时候,动态添加input class属性失效, 检查原因是因为之前对此input 使用了  input[type='checkbox'] 应该给其定义一个CLASS,其后面动态添加C ...

  6. Python正则表达式2

  7. yarn源代码

    Modules-------YARN consists of multiple modules. The modules are listed below as per the directory s ...

  8. objective-C: nonatomic retain copy assgin 等属性详解

    http://my.oschina.net/u/728866/blog/90798 property,可以提供的功能有:提供成员变量的访问方法的声明.控制成员变量的访问权限.控制多线程时成员变量的访问 ...

  9. Hdu 3177 Crixalis's Equipment

    Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  10. EasyPHP的Apache报错

    今天安装了最新版本的软件:EasyPHP-DevServer-14.1VC11-install.exe 启动报错: 打开Cport软件: 可见80端口被系统占用,导致Apache不能启动. (1)手动 ...