简体   繁体   中英

Using Lua with C++

I'm trying to embed lua in ac program, but I'm having problems to compile the code. I have installed everything lua 5.2 related in synaptic and when tried to compile this:

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

show the folowing errors

Could not find -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

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.

Of course, pkg-config can also tell you the -CFLAGS for the package with

pkg-config --cflags lua5.2

The man page is quite readable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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