Cmake with Lua lib

I'm trying to add Lua library in Cmake, and don't know how to do it properly.

Sample is taken from here (https://www.lua.org/pil/24.1.html).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <string.h>

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

int main(void) {
    puts("lua interpretor:");
    char buff[256];
    int error;
    lua_State *L = luaL_newstate(); /* opens Lua */
    luaL_openlibs(L); /* opens the standard libraries */
    while (fgets(buff, sizeof(buff), stdin) != NULL) {
        error = luaL_loadbuffer(L, buff, strlen(buff), "line") ||
                lua_pcall(L, 0, 0, 0);
        if (error) {
            fprintf(stderr, "%s", lua_tostring(L, -1));
            lua_pop(L, 1); /* pop error message from the stack */
        }
    }
    lua_close(L);
    return 0;
}


it works if I compile it by "hands"

 
clang -W -Wall -g -o main main.c  -I/usr/local/include -L/usr/local/lib/lua/5.1 -llua
Topic archived. No new replies allowed.