安裝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,問題解決
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章