mpx / lua-cjson

Lua CJSON is a fast JSON encoding/parsing module for Lua
https://kyne.au/~mark/software/lua-cjson.php
MIT License
924 stars 474 forks source link

Symbol not found: _lua_objlen #56

Open ktalebian opened 6 years ago

ktalebian commented 6 years ago

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 ?
jamespenick commented 6 years ago

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.

MaG21 commented 6 years ago
$ luarocks remove lua-cjson
$ luarocks install lua-cjson 2.1.0-1
peter-evans commented 6 years ago

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

kidlj commented 5 years ago

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.

e-moe commented 4 years ago

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

VVatashi commented 4 years ago

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 ?
MaMo7x commented 2 years ago

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 . .

mecampbellsoup commented 2 years ago

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

kaklakariada commented 2 years ago

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.