Embedding lua - first steps

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Embedding lua - first steps

Ervin Hegedüs
Hi Lua-l list,

I'm new here, I'm looking for the embedding solutions, and I found Lua - it's easy and likeable language.

I've found several example to embed Lua to C (and C++ code), but I can't compile them on my Linux Mint 17.1.

The last example was here:

https://www.debian-administration.org/article/264/Embedding_a_scripting_language_inside_your_C/C_code

There is the first example with 26 lines of code, and the gcc command. I've tried several examples, but I always got this error:

luainit.c:(.text+0x10): undefined reference to `lua_open'
luainit.c:(.text+0x26): undefined reference to `luaopen_base'
luainit.c:(.text+0x35): undefined reference to `luaopen_table'


or in other snippets from other examles:

luaload.c:(.text+0x1c): undefined reference to `luaL_newstate'
luaload.c:(.text+0x33): undefined reference to `luaL_openlibs'
luaload.c:(.text+0x44): undefined reference to `luaL_loadfile'
...

I've tried them with lua5.2, lua5.1, and now the current version is lua5.0. The gcc command is exactly:

gcc -o luainit -Wall `lua-config --include --libs` luainit.c

but I've tried it with this too:

gcc -o luainit -Wall `lua-config --include --libs` -lm -ldl luainit.c

The output of "lua-config -include --libs" is this:

-I/usr/include/lua50 -L/usr/include -llualib50 -llua50

What em I missing?


Thanks,

a.
Reply | Threaded
Open this post in threaded view
|

Re: Embedding lua - first steps

Laurent FAILLIE
Hi,

Le Jeudi 10 septembre 2015 10h39, Ervin Hegedüs <[hidden email]> a écrit :

>The output of "lua-config -include --libs" is this:
>
> -I/usr/include/lua50 -L/usr/include -llualib50 -llua50

It looks to me -L is wrong : libraries are in /usr/lib (or lib32 or lib63) but clearly not in /usr/include.

In my own code, running under Gentoo, I simply add '-llua' and everything is working fine (see https://github.com/destroyedlolo/Marcel as example).

Best regards,

Laurent


Reply | Threaded
Open this post in threaded view
|

Re: Embedding lua - first steps

Philipp Janda
In reply to this post by Ervin Hegedüs
Am 10.09.2015 um 10:39 schröbte Ervin Hegedüs:
> Hi Lua-l list,

Hi!

>
> I'm new here, I'm looking for the embedding solutions, and I found Lua -
> it's easy and likeable language.
>
> I've found several example to embed Lua to C (and C++ code), but I can't
> compile them on my Linux Mint 17.1.
>
> The last example was here:
>
> https://www.debian-administration.org/article/264/Embedding_a_scripting_language_inside_your_C/C_code
>
> There is the first example with 26 lines of code, and the gcc command. I've
> tried several examples, but I always got this error:
>
> luainit.c:(.text+0x10): undefined reference to `lua_open'
> luainit.c:(.text+0x26): undefined reference to `luaopen_base'
> luainit.c:(.text+0x35): undefined reference to `luaopen_table'
>
>
> or in other snippets from other examles:
>
> luaload.c:(.text+0x1c): undefined reference to `luaL_newstate'
> luaload.c:(.text+0x33): undefined reference to `luaL_openlibs'
> luaload.c:(.text+0x44): undefined reference to `luaL_loadfile'
> ...
>
> I've tried them with lua5.2, lua5.1, and now the current version is lua5.0.
> The gcc command is exactly:
>
> gcc -o luainit -Wall `lua-config --include --libs` luainit.c
>
> but I've tried it with this too:
>
> gcc -o luainit -Wall `lua-config --include --libs` -lm -ldl luainit.c
>
> The output of "lua-config -include --libs" is this:
>
> -I/usr/include/lua50 -L/usr/include -llualib50 -llua50
>
> What em I missing?
>

Try moving the source file in front of the libraries like so:

     gcc -o luainit -Wall luainit.c `lua-config --include --libs` -lm -ldl

>
> Thanks,
>
> a.
>

Philipp




Reply | Threaded
Open this post in threaded view
|

Re: Embedding lua - first steps

Ervin Hegedüs
Hi Philipp,

On Thu, Sep 10, 2015 at 11:14:40AM +0200, Philipp Janda wrote:
> Am 10.09.2015 um 10:39 schröbte Ervin Hegedüs:
[...]

> >luaload.c:(.text+0x1c): undefined reference to `luaL_newstate'
> >luaload.c:(.text+0x33): undefined reference to `luaL_openlibs'
> >luaload.c:(.text+0x44): undefined reference to `luaL_loadfile'
> >...
> >
> >I've tried them with lua5.2, lua5.1, and now the current version is lua5.0.
> >The gcc command is exactly:
> >
> >gcc -o luainit -Wall `lua-config --include --libs` luainit.c
> >
> >but I've tried it with this too:
> >
> >gcc -o luainit -Wall `lua-config --include --libs` -lm -ldl luainit.c
> >
> >The output of "lua-config -include --libs" is this:
> >
> >-I/usr/include/lua50 -L/usr/include -llualib50 -llua50
> >
> >What em I missing?
> >
>
> Try moving the source file in front of the libraries like so:
>
>     gcc -o luainit -Wall luainit.c `lua-config --include --libs` -lm -ldl

thanks for your tip, that solves my problem.


regards,


a.