我正在使用lua-cjson

package.path = package.path .. ";../?.lua"
local json = require('cjson')

我得到:
lua: error loading module 'cjson' from file '/usr/local/lib/lua/5.3/cjson.so':
        dlopen(/usr/local/lib/lua/5.3/cjson.so, 6): Symbol not found: _lua_objlen
  Referenced from: /usr/local/lib/lua/5.3/cjson.so
  Expected in: flat namespace
 in /usr/local/lib/lua/5.3/cjson.so
stack traceback:
        [C]: in ?
        [C]: in function 'require'
        log.lua:6: in main chunk
        [C]: in ?

有任何想法吗?使用lua 5.3

最佳答案

@James Penick提到降级到 2.1.0-1

luarocks remove lua-cjson
luarocks install lua-cjson 2.1.0-1

Installing https://luarocks.org/lua-cjson-2.1.0-1.src.rock
env MACOSX_DEPLOYMENT_TARGET=10.8 gcc -O2 -fPIC -I/usr/local/include -c lua_cjson.c -o lua_cjson.o
In file included from lua_cjson.c:47:
./fpconv.h:15:20: warning: inline function 'fpconv_init' is not defined [-Wundefined-inline]
extern inline void fpconv_init();
                   ^
lua_cjson.c:1359:5: note: used here
    fpconv_init();
    ^
1 warning generated.
env MACOSX_DEPLOYMENT_TARGET=10.8 gcc -O2 -fPIC -I/usr/local/include -c strbuf.c -o strbuf.o
env MACOSX_DEPLOYMENT_TARGET=10.8 gcc -O2 -fPIC -I/usr/local/include -c fpconv.c -o fpconv.o
env MACOSX_DEPLOYMENT_TARGET=10.8 gcc -bundle -undefined dynamic_lookup -all_load -o cjson.so -L/usr/local/lib lua_cjson.o strbuf.o fpconv.o
lua-cjson 2.1.0-1 is now installed in /usr/local (license: MIT)

问题与安装 lua-cjson-2.1.0.6-1 时的警告消息有关
Installing https://luarocks.org/lua-cjson-2.1.0.6-1.src.rock
env MACOSX_DEPLOYMENT_TARGET=10.8 gcc -O2 -fPIC -I/usr/local/include -c lua_cjson.c -o lua_cjson.o
lua_cjson.c:743:19: warning: implicit declaration of function 'lua_objlen' is invalid in C99 [-Wimplicit-function-declaration]
            len = lua_objlen(l, -1);
                  ^
1 warning generated.

关于lua - 找不到符号: _lua_objlen,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50281201/

10-12 03:56