安装cjson遇到的问题

安装 cjson
下载地址:https://www.kyne.com.au/~mark/software/download/lua-cjson-2.1.0.tar.gz
如果不能在linux下使用wget下载,可以先在windows浏览器下载,再上传到linux
tar -zxvf lua-cjson-2.1.0.tar.gz
cd lua-cjson-2.1.0
make
make install
----------------------------------------------------------------

安装过程遇到的问题
问题一:
make时报错如下:
[root@MQ_96_86 lua-cjson-2.1.0]# make

cc -c -O3 -Wall -pedantic -DNDEBUG  -I/usr/local/include -fpic -o lua_cjson.o lua_cjson.c
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
lua_cjson.c:348: error: expected ‘)’ before ‘*’ token
lua_cjson.c:359: error: expected ‘)’ before ‘*’ token
lua_cjson.c:371: error: expected ‘)’ before ‘*’ token
lua_cjson.c:446: error: expected ‘)’ before ‘*’ token
lua_cjson.c:461: error: expected ‘)’ before ‘*’ token
解决方法:
  1. 首先openresty的安装目录下找到 lauxlib.h 和 lua.h  文件的所在目录。/opt/openresty/luajit/include/luajit-2.1/lua.h,/opt/openresty/luajit/include/luajit-2.1/lauxlib.h
  2. 编辑lua_cjson目录中的 Makefile文件,大概在20行 找到 “LUA_INCLUDE_DIR =”  把等号后面的目录改成 /opt/openresty/luajit/include/luajit-2.1
以上问题解决完毕
问题2:
解决上面的问题后,make时依然报错,错误如下:
[root@MQ_96_86 lua-cjson-2.1.0]# make
cc -c -O3 -Wall -pedantic -DNDEBUG  -I/opt/openresty/luajit/include/luajit-2.1 -fpic -o lua_cjson.o lua_cjson.c
lua_cjson.c:1298: error: static declaration of ‘luaL_setfuncs’ follows non-static declaration
/opt/openresty/luajit/include/luajit-2.1/lauxlib.h:88: note: previous declaration of ‘luaL_setfuncs’ was here
make: *** [lua_cjson.o] Error 1

错误的大概意思是:luaL_setfuncs 这个方法 接口定义时不是静态的方法,实现时,却定义成了静态方法
解决方法:
  1. 直接在Makefile所在的目录执行查找字符串 命令:find . -type f -name "*.*" | xargs grep "luaL_setfuncs" 结果如下
    [root@MQ_96_86 lua-cjson-2.1.0]# find . -type f -name "*.*" | xargs grep "luaL_setfuncs"
    ./lua_cjson.c: * luaL_setfuncs() is used to create a module table where the functions have
    ./lua_cjson.c:static void luaL_setfuncs (lua_State *l, const luaL_Reg *reg, int nup)
    ./lua_cjson.c:    luaL_setfuncs(l, reg, 1);

  2. 发现只有lua_cjson.c 文件中包含上面字符串,所以编辑 lua_cjson.c
    根据错误提示大概在88行,也可以vim打开文件后 查找字符串 luaL_setfuncs 定位到定义此方法的一行,将static关键字去掉,保存退出
重新make,问题解决

猜你喜欢

转载自blog.csdn.net/kunlilove521/article/details/79992579