lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Please ignore my post..
I found the answer 3 minutes later.
My apologies.
(had to compile with -Wl,-E)

On Thu, Apr 2, 2020 at 6:01 AM Michael Aganier <michaelaganier@gmail.com> wrote:
>
> Hi, I want to call a C function from within the same executable as my
> lua VM through FFI but I get undefined symbol error. Why?
>
> file: my_func.lua
> local ffi = require("ffi")
> ffi.cdef[[
> void my_func(void);
> ]]
> ffi.C.my_func()
>
> file: main.c
> #include <luajit-2.0/lauxlib.h>
> #include <luajit-2.0/lua.h>
> #include <luajit-2.0/lualib.h>
>
> extern void my_func(void)
> {
>         printf("hello\n");
> }
>
> int main(int argc, char **argv)
> {
>         lua_State *L = luaL_newstate();
>
>         luaL_openlibs(L);
>
>         if (luaL_dofile(L, "my_func.lua")) {
>                 printf("err: %s\n", lua_tostring(L, -1));
>         }
>         lua_close(L);
>
>         return 0;
> }
>
> ran with:
> $ gcc main.c -lluajit-5.1
> $ ./a.out
>
> output:
> $ err: my_func.lua:6: /usr/lib/libluajit-5.1.so.2: undefined symbol: my_func