Компилировать встроенный lua в C - PullRequest
5 голосов
/ 06 ноября 2011

Привет всем, я нашел этот код, который встраивает Lua в C, и я не могу понять, как заставить GCC его скомпилировать.У меня установлен Lua, но как мне связать библиотеки Lua?

Вот код, который я нашел:

            #include <stdio.h>
            #include "lua.h"
            #include "lualib.h"
            #include "lauxlib.h"

            /* lua interpreter */
            lua_State* l;

            int main () {
            int dofile;

            /* initialize lua */
            l = lua_open();

            /* load lua libraries */
            luaL_openlibs(l);

            /* run the hello.lua script */
            dofile = luaL_dofile(l, "hello.lua");

            if (dofile == 0) {
            /* call foo */
            lua_getglobal(l,"foo");
            lua_call(l,0,0);
            }
            else {
            printf("Error, unable to run hello.lua\n");
            }

            /* cleanup Lua */
            lua_close(l);

            return 0;
            }

Как мне это скомпилировать?

Я пытаюсь эту команду для компиляции

gcc -o embed_hello -L/users/etrosclair/Downloads/lua-5.1.4 -I/users/etrosclair/Downloads/lua-5.1.4 luaTest.c

Вот ошибка:

Undefined symbols for architecture x86_64:
  "_luaL_newstate", referenced from:
      _main in ccF0995Q.o
  "_luaL_openlibs", referenced from:
      _main in ccF0995Q.o
  "_luaL_loadfile", referenced from:
      _main in ccF0995Q.o
  "_lua_pcall", referenced from:
      _main in ccF0995Q.o
  "_lua_getfield", referenced from:
      _main in ccF0995Q.o
  "_lua_call", referenced from:
      _main in ccF0995Q.o
  "_lua_close", referenced from:
      _main in ccF0995Q.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

Все библиотеки lua и заголовки находятся в папке lua-5.1.4, файлы .oи там тоже.

Спасибо

Спасибо

1 Ответ

8 голосов
/ 06 ноября 2011

Зависит от статической или динамической компиляции.

Для статических добавьте -llua (или lua5.1 или lua51; в зависимости от ваших настроек)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...