0

I'm trying to embed lua in a c 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?

5
  • use -L/path/to/lib Commented Aug 17, 2014 at 15:32
  • Please decide: Shall that be a C or a C++ program? BTW: You can compile Lua both as C as well as C++, though I would leep it C. Also, neither <stdio.h> nor <string.h> should be wrapped in an extern "C"-block. Commented Aug 17, 2014 at 15:33
  • @redFIVE Like this? g++ main.cpp -L/usr/lib/lua/5.2/ -llua . Still not find -llua Commented Aug 17, 2014 at 15:41
  • Is there a liblua.so in that directory? Commented Aug 17, 2014 at 15:48
  • @Deduplicator No o.O . there is a rdd.so and no liblua.so anywhere im my pc. Why not? I have installed everything lua5.2 disponible. Commented Aug 17, 2014 at 15:57

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.