zoukankan      html  css  js  c++  java
  • luajit 安装cjson

    最近需要升级原有服务器的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.0.tar.gz 
    
    cd  lua-cjson-2.1.0

    make

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

    lua_cjson.c:43:17: error: lua.h: No such file or directory
    lua_cjson.c:44:21: error: lauxlib.h: No such file or directory
    lua_cjson.c:192: error: expected ‘)’ before ‘*’ token
    lua_cjson.c:206: error: expected ‘)’ before ‘*’ token
    lua_cjson.c:218: error: expected ‘)’ before ‘*’ token
    lua_cjson.c:237: error: expected ‘)’ before ‘*’ token
    lua_cjson.c:266: error: expected ‘)’ before ‘*’ token
    lua_cjson.c:279: error: expected ‘)’ before ‘*’ token
    lua_cjson.c:288: error: expected ‘)’ before ‘*’ token
    lua_cjson.c:296: error: expected ‘)’ before ‘*’ token
    lua_cjson.c:304: error: expected ‘)’ before ‘*’ token
    lua_cjson.c:336: 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.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.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.0/include/luajit-2.0 -fpic -o lua_cjson.o lua_cjson.c
    cc -c -O3 -Wall -pedantic -DNDEBUG  -I/opt/luajit-2.0.0/include/luajit-2.0 -fpic -o strbuf.o strbuf.c
    cc -c -O3 -Wall -pedantic -DNDEBUG  -I/opt/luajit-2.0.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 755 //opt/luajit-2.0.0/lib/lua/5.1/cjson.so

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

  • 相关阅读:
    Application Loader上传app程序
    Xcode解决代码高亮、语法提示、错误警告等功能失效的解决方法
    c#上iOS apns p12文件制作记录 iOS推送证书制件
    iOS开发~CocoaPods使用详细说明
    ios实现屏幕旋转的方法
    View页面内容的旋转,在某些情况下可替代屏幕旋转使用
    集成乐视点播功能的注意事项
    NSMutableAttributedString 富文本删除线的用法
    Objective-c的@property 详解
    ASIHttpRequest addRequestHeader的处理
  • 原文地址:https://www.cnblogs.com/dongxiao-yang/p/5293120.html
Copyright © 2011-2022 走看看