使用源码编译 Lua 并创建 C 模块
2016-11-28 17:29:46
收藏:0
阅读:86
评论:1
我思考着从源代码中编译 Lua,然后创建一个 C 模块。 我已经成功编译了 Lua,但是我无法构建我的 C 模块。
所以我这样编译了 Lua:
gcc -o Lua *.c -Os -std=c99
像这样编译我的模块:
gcc -Wall -bundle -undefined dynamic_lookup -o module.so -I. module.c
但是这里有一些错误:
Undefined symbols for architecture x86_64:
"_lua_pushcclosure", referenced from:
_luaopen_module in module-fb0b1f.o
"_lua_pushnumber", referenced from:
_super in module-fb0b1f.o
"_lua_setglobal", referenced from:
_luaopen_module in module-fb0b1f.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
C 模块本身:
#include "lua.h"
static int super(lua_State* L) {
lua_pushnumber(L, 5);
return 1;
}
int luaopen_module(lua_State* L) {
lua_register(L, "super", super);
return 0;
}
我的 Lua 脚本:
require("module")
print(super())
我在基于 Unix 的系统(Mac)上,但我也希望它可以在 Linux 上运行。
编辑:
通过输入 -bundle -undefined dynamic_lookup 替换 -shared(感谢 lhf),解决了编译 C 模块的问题,但我无法在 Lua 中导入模块。
> require("module")
error loading module 'module' from file './module.so':
dynamic libraries not enabled; check your Lua installation
另外一件事情:
这似乎只是一个快速的修复;-bundle -undefined dynamic_lookup。这在 Linux 上不起作用。我想在基于 Unix 的系统上找到解决方案。
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?

从 lua.org 下载 Lua 并使用
make macosx编译 Lua。参见 入门指南。使用
-bundle -undefined dynamic_lookup代替-shared来构建module.so。使用
require"module"将其加载到 Lua 中。调用
super。请确保您运行的是上述编译好的
lua程序,而不是其他安装的版本。