Search code examples
lualuarocks

luarocks lyaml installation error


on luarocks install lyaml I get following error:

Error: Could not find expected file libyaml.a, or libyaml.so, or libyaml.so.* for YAML -- you may have to install YAML in your system and/or pass YAML_DIR or YAML_LIBDIR to the luarocks command. Example: luarocks install lyaml YAML_DIR=/usr/local

lua version: 5.1.5

How do I install YAML in system to start using lyaml rock?


Solution

  • Whenever you get a LuaRocks message saying you may have to install ____ in your system it means the rockspec has an external dependency.

    Installing external dependencies

    The way to satisfy this dependency is to install the package using the appropriate means of your system: if using Debian/Ubuntu, with apt-get, if using macOS, probably using Homebrew, etc.

    Note that for building code, in systems that have the concept of dev packages, such as most Linux distributions, you need to install both the main library package and the dev package (which contains the header files for compilation). For example, for Debian/Ubuntu, to satisfy this dependency you need to run apt-get install libyaml libyaml-dev.

    Unfortunately, the names are not fully consistent across systems and distros: a module may be called ncurses-dev in one system, libncurses6w-dev in another, etc. So in your particular case you'll have to search around for the right name of the YAML library (the package providing libyaml) in your system.

    Once the external dependency is installed...

    Installing a library with the system package manager will usually install the necessary files in locations that are automatically detected by LuaRocks, so running

    luarocks install lyaml

    again should find the libyaml files and proceed with the installation.

    If external dependencies are installed in a non-standard location

    If that fails, you can find the directories where the library (libyaml.so) and header (yaml.h) were installed and tell LuaRocks about it. For example, if libyaml.so was installed in some non-standard locations such as /opt/lib/yaml/libyaml.so and the header in /opt/include/yaml-1/yaml.h you would do this:

    luarocks install lyaml YAML_LIBDIR=/opt/lib/yaml/ YAML_INCDIR=/opt/include/yaml-1/

    This kind of situation happens when a system installs headers or libraries in a subdirectory. For example, for LuaSec on the Mac, which uses OpenSSL, it is sometimes necessary to use pathnames like this:

    luarocks install luasec OPENSSL_INCDIR=/usr/local/opt/openssl/include OPENSSL_LIBDIR=/usr/local/opt/openssl/lib