Discussion:
Embedding lua - first steps
Ervin Hegedüs
2015-09-10 08:39:01 UTC
Permalink
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.
Laurent FAILLIE
2015-09-10 09:07:13 UTC
Permalink
Hi,
Post by Ervin Hegedüs
-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
Philipp Janda
2015-09-10 09:14:40 UTC
Permalink
Post by Ervin Hegedüs
Hi Lua-l list,
Hi!
Post by Ervin Hegedüs
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.
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
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'
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.
gcc -o luainit -Wall `lua-config --include --libs` luainit.c
gcc -o luainit -Wall `lua-config --include --libs` -lm -ldl luainit.c
-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
Post by Ervin Hegedüs
Thanks,
a.
Philipp
Ervin Hegedüs
2015-09-10 10:43:46 UTC
Permalink
Hi Philipp,
[...]
Post by Philipp Janda
Post by 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.
gcc -o luainit -Wall `lua-config --include --libs` luainit.c
gcc -o luainit -Wall `lua-config --include --libs` -lm -ldl luainit.c
-I/usr/include/lua50 -L/usr/include -llualib50 -llua50
What em I missing?
gcc -o luainit -Wall luainit.c `lua-config --include --libs` -lm -ldl
thanks for your tip, that solves my problem.


regards,


a.

Continue reading on narkive:
Loading...