【问题标题】:Using Lua with C++在 C++ 中使用 Lua
【发布时间】:2014-10-10 14:47:38
【问题描述】:

我正在尝试将 lua 嵌入到 c 程序中,但我在编译代码时遇到了问题。我已经在突触中安装了所有与 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

做什么?

【问题讨论】:

  • 使用-L/path/to/lib
  • 请决定:应该是 C 程序还是 C++ 程序?顺便说一句:您可以将 Lua 编译为 C 和 C++,尽管我会使用 C。此外,&lt;stdio.h&gt;&lt;string.h&gt; 都不应该包含在 extern "C"-block 中。
  • @redFIVE 喜欢这个? g++ main.cpp -L/usr/lib/lua/5.2/ -llua 。还是找不到-llua
  • 那个目录里有liblua.so吗?
  • @Deduplicator No o.O 。我的电脑上的任何地方都有 rdd.so 并且没有 liblua.so。为什么不?我已经安装了所有 lua5.2 disponible。

标签: c++ lua embed


【解决方案1】:

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

尤其是正确安装 lua5.2 库后,您可以使用

pkg-config -libs lua5.2

在我的系统上它输出

-llua5.2

使用它或 pkg-config 的输出(反引号)作为链接器参数。

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

pkg-config --cflags lua5.2

手册页非常易读。

【讨论】:

    猜你喜欢
    • 2012-02-15
    • 2016-11-20
    • 2019-02-18
    • 1970-01-01
    • 2014-09-27
    • 2010-11-27
    • 2021-02-25
    • 2011-05-30
    相关资源
    最近更新 更多