mpx / lua-cjson

Lua CJSON is a fast JSON encoding/parsing module for Lua

Home Page:https://kyne.au/~mark/software/lua-cjson.php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Symbol not found: _lua_objlen

ktalebian opened this issue · comments

I'm requiring the module using

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

And I'm getting:

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 ?

I'm seeing the same issue on alpine linux with with version 2.1.0.6-1 of lua-cjson, I'm currently working around the issue by explicitly specifying version 2.1.0-1.

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

lua-cjson on luarocks seems to be Openresty's version, not this code base. See this issue there:
openresty#36

I'm having the same issue on macOS with Lua-5.3.5.

I have to remove the latest lua-cjson(2.1.0.6-1) and install a previous version(2.1.0-1) instead.

same issue: macOS 10.15.1 (19B88); Lua-5.3.5; lua-cjson(2.1.0.6-1)

commented

Still have the same problem on the Arch linux when installing it from the luarocks.

$ sudo luarocks install lua-cjson
Installing https://luarocks.org/lua-cjson-2.1.0.6-1.src.rock

gcc -O2 -fPIC -I/usr/include -c lua_cjson.c -o lua_cjson.o
lua_cjson.c: In function 'json_append_data':
lua_cjson.c:743:19: warning: implicit declaration of function 'lua_objlen'; did you mean 'lua_len'? [-Wimplicit-function-declaration]
  743 |             len = lua_objlen(l, -1);
      |                   ^~~~~~~~~~
      |                   lua_len
gcc -O2 -fPIC -I/usr/include -c strbuf.c -o strbuf.o
gcc -O2 -fPIC -I/usr/include -c fpconv.c -o fpconv.o
gcc -shared -o cjson.so lua_cjson.o strbuf.o fpconv.o
lua-cjson 2.1.0.6-1 is now installed in /usr (license: MIT)

And then when I run a script:

$ lua test.lua
lua: error loading module 'cjson' from file '/usr/lib/lua/5.3/cjson.so':
	/usr/lib/lua/5.3/cjson.so: undefined symbol: lua_objlen
stack traceback:
	[C]: in ?
	[C]: in function 'require'
	test.lua:1: in main chunk
	[C]: in ?

I found the fix . . . http://lua-users.org/lists/lua-l/2018-03/msg00447.html on this link it is stated that lua_objlen was renamed to lua_rawlen . . . so renaming lua_objlen:lua_cjson.c:743 to lua_rawlen solves the issue.
Here is what I did to build the latest release . . .
$ luarocks download lua_cjson
$ luarocks unpack lua_cjson
$ cd lua-cjson-2.1.0.6-1/lua-cjson
edit the lua_cjson.c file using your favourite editor and change lua_objlen -> lua_rawlen
then,
$ luarocks make
BOOM! it compiles fine . .

This issue is still open after almost 4 years, is this project not maintained?

I managed to install the latest version with the following command:

luarocks install lua-cjson --local "CFLAGS=-O3 -Wall -pedantic -DNDEBUG -DLUA_COMPAT_5_3"

The important part is -DLUA_COMPAT_5_3.