1
votes

I'm new at Lua and writing bindings in general. At the moment I'm just trying to compile the first example found here (with the functions updated to Lua 5.1).

#include <stdio.h>

#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"

/* the Lua interpreter */
lua_State* L;

int main ( int argc, char *argv[] )
{
    /* initialize Lua */
    L = luaL_newstate();

    /* load various Lua libraries */
    luaL_openlibs(L);
        luaopen_table(L);
        luaopen_io(L);
        luaopen_string(L);
        luaopen_math(L);

    /* cleanup Lua */
    lua_close(L);

    return 0;
}

When I compile using gcc -o init init.c -Wall -I/usr/local/include -L/usr/local/lib -llua -lliblua I get the following error:

.../../i486-pc-linux-gnu/bin/ld: cannot find -lliblua
collect2: ld returned 1 exit status

The file liblua.a is in /usr/local/lib, but for some reason the compiler can't find it? What am I doing wrong?

2
According to lua.org/pil/24.1.html you shouldn't be calling luaopen_table, _io, _string, etc. - Cogwheel

2 Answers

7
votes

The liblua.a file is included by the -llua parameter. Specifying -lliblua attempts to find a libliblua.a file that does not exist. So, simply remove -lliblua from your build command.

1
votes

There's no -lliblua in 5.1.