无法与 Linux 上的 Lua 库链接

标签 c linux gcc lua

我已经使用 make posix 在 Debian x86-64 上编译了 Lua 5.2,并且我正在尝试使用命令 gcc -ldl -llua main.c

编译以下内容
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
int main() {  
  lua_State *L = luaL_newstate(); 
  luaL_openlibs(L);  
  dofile("test.lua");   
  return 0;
}

并获取对 lua 函数的未解析引用

最佳答案

假设你的错误是

undefined reference to `dofile'

那么你的问题是 dofile 是一个 lua 函数而不是 C 函数。

你可能需要 luaL_dofile(L, "test.lua")

关于无法与 Linux 上的 Lua 库链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19941127/

相关文章:

c - 我不明白为什么我的代码会导致堆栈崩溃

c - 按索引从c中的字符串中删除字符

linux - 通过 linux x86-64 函数调用保留了哪些寄存器

node.js - 如何捕获彩色生成的进程输出并通过 nodejs 发送到浏览器?

linux - 使用 sed 替换字符串

gcc - 使用python3安装matplotlib时gcc出错

c++ - 在 Windows 中将 VS2005 静态库与 gcc 链接

c - 链接静态库

c - Gtk3 和 cairo 动画 twitch

c - GSL 多个错误处理程序定义链接时出错