mpx / lua-cjson

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

Lua-Cjson cannot locate symbol "floor" in Termux #82

Closed mbekkomo closed 1 year ago

mbekkomo commented 2 years ago

Hello. So when I try to run my Discord bot using Lacord, the Lua-Cjson module ran into a problem.

You can see it in the image :

Screenshot_202206164-151950

mpx commented 2 years ago

You will need to link with libm (-lm) for the floor function.

mbekkomo commented 2 years ago

How?

masrafi115 commented 1 year ago

there's no option by default to link mathlib because we can't add custom compile flags by default.

there's a module that provides custom build. []()https://github.com/osch/luarocks-build-extended

first install the module from luarocks

you need to specify flags by libflag_extras. also set build type type = "extended"

so i edited my rockspec and added flags

package = "lua-cjson"
version = "2.1.0.10-1"

source = {
    url = "git+https://github.com/openresty/lua-cjson",
    tag = "2.1.0.10",
}

description = {
    summary = "a fast json encoding/parsing module",
    detailed = [[
        the lua cjson module provides json support for lua. it features:
        - fast, standards compliant encoding/parsing routines
        - full support for json with utf-8, including decoding surrogate pairs
        - optional run-time support for common exceptions to the json specification
          (infinity, nan,..)
        - no dependencies on other libraries
    ]],
    homepage = "http://www.kyne.com.au/~mark/software/lua-cjson.php",
    license = "mit"
}

dependencies = {
    "lua >= 5.1"
}

build = {
    type = "extended",
    modules = {
        cjson = {
            sources = { "lua_cjson.c", "strbuf.c", "fpconv.c" },

            defines = {
-- luarocks does not support platform specific configuration for solaris.
-- uncomment the line below on solaris platforms if required.
--                "use_internal_isinf"
            }
        }
    },
    install = {
        lua = {
            ["cjson.util"] = "lua/cjson/util.lua"
        },
        bin = {
            json2lua = "lua/json2lua.lua",
            lua2json = "lua/lua2json.lua"
        }
    },
    -- override default build options (per platform)
    platforms = {
        linux = { modules = { cjson = { variables = {
                        libflag_extras = { 
                            "-lm", "" 
                        }
                    } } } }
    },
    copy_directories = { "tests" }
}

-- vi:ai et sw=4 ts=4:

and then install

luarocks install lua-cjson-2.1.0.10-1.rockspec

i tested on my device and it works well.

mbekkomo commented 1 year ago

I have found the solution, so you don't need to. I'm closing this issue to prevent any other answers