简体   繁体   English

在C ++中使用Lua

[英]Using Lua with C++

I'm trying to embed lua in ac program, but I'm having problems to compile the code. 我正在尝试将lua嵌入到ac程序中,但是在编译代码时遇到了问题。 I have installed everything lua 5.2 related in synaptic and when tried to compile this: 我已经在突触中安装了与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);
}

and compile using 并使用编译

g++ main.cpp -llua g ++ main.cpp -llua

show the folowing errors 显示以下错误

Could not find -llua 找不到-llua

what do? 做什么?

There are tools you can use to find the proper compiler / linker switches for a library. 您可以使用一些工具来为库找到合适的编译器/链接器开关。

In particular, with a proper installation of the lua5.2 libraries you can use 特别是,通过正确安装lua5.2库,您可以使用

pkg-config -libs lua5.2

On my system it outputs 在我的系统上它输出

-llua5.2

Use this, or the output of pkg-config (backticked) as your linkers argument. 使用它,或将pkg-config的输出(反引号)用作链接器参数。

Of course, pkg-config can also tell you the -CFLAGS for the package with 当然,pkg-config也可以告诉您-CFLAGS的软件包

pkg-config --cflags lua5.2

The man page is quite readable. 手册页可读性强。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM