在c++中使用Lua

Using Lua with C++

本文关键字:Lua c++      更新时间:2023-10-16

我正试图在c程序中嵌入lua,但我在编译代码时遇到了问题。我已经在synaptic中安装了lua 5.2相关的所有内容,当我试图编译这个时:

extern "C"{
#include <stdio.h>
#include <string.h>
#include "lua5.2/lua.h"
#include "lua5.2/lauxlib.h"
#include "lua5.2/lualib.h"
}
int main(int argc, char* argv[])
{
    lua_State *lua_state;
    lua_state = luaL_newstate();
    lua_close(lua_state);
}

和使用

编译

g++ main.cpp -llua

显示以下错误

找不到-llua

什么?

您可以使用一些工具来查找库的适当编译器/链接器开关。

特别是,在正确安装了lua5.2库之后,您可以使用

pkg-config -libs lua5.2

在我的系统上它输出

-llua5.2

使用这个,或者pkg-config的输出(反勾)作为您的链接器参数。

当然,pkg-config也可以告诉你

包的-CFLAGS
pkg-config --cflags lua5.2

手册页很好读