mips-openwrt-linux-gcc: 链接 Lua lib 出错

我想在 OpenWrt 14.07 上的 C 应用程序中调用 Lua 函数。在交叉编译项目时,我无法在工具链中找到 lua 的头文件和 .so 文件。因此,我从 Ubuntu 14.04 复制了 lua51 文件夹和从目标操作系统中复制了 liblua.so 到工具链中。然后尝试编译项目,但是我收到了未定义引用错误。

mips-openwrt-linux-gcc airkiss.c luaconf.c -lpthread -llua libairkiss_log.a
-L. -o airkiss -Wl,-rpath-link=/opt/OpenWrt-Toolchain-ar71xx-for-mips_34kc-gcc-4.8-linaro_uClibc-0.9.33.2/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib

我收到了以下错误:

luaconf.c:(.text+0x18): undefined reference to `luaL_newstate'
luaconf.c:(.text+0x28): undefined reference to `luaL_openlibs'
luaconf.c:(.text+0x3c): undefined reference to `luaL_loadfile'
luaconf.c:(.text+0x54): undefined reference to `lua_getfield'
luaconf.c:(.text+0x64): undefined reference to `lua_pushstring'
luaconf.c:(.text+0x74): undefined reference to `lua_pushstring'
luaconf.c:(.text+0x8c): undefined reference to `lua_pcall'
luaconf.c:(.text+0xa0): undefined reference to `lua_tolstring'
luaconf.c:(.text+0xc0): undefined reference to `lua_close'

有人知道如何修复它吗?谢谢!

点赞
用户5308565
用户5308565

最好的方法是使用OpenWrt样式的Makefile项目来编译您的代码。

请参考 feeds/packages/multimedia/xupnpd/Makefile - 它也使用了liblua。

这个手册会对您有所帮助: https://wiki.openwrt.org/doc/devel/packages

2015-12-22 08:01:22
用户4983801
用户4983801

似乎 lua 已经默认开启了。请检查您的 .config 文件中 CONFIG_PACKAGE_liblua 和 CONFIG_PACKAGE_lua 是否为 'y'。

默认情况下,头文件位于 staging_dir/target-mips_r2_uClibc-0.9.33.2/usr/include,库文件位于 staging_dir/target-mips_r2_uClibc-0.9.33.2/usr/lib。

还要检查是否已经执行了完整构建。

2015-12-25 03:53:02