Skip to content
Advertisement

Linker can’t find Lua library definition

So, I’m relatively new to C++ and I’ve been trying to run Lua files in my C++ project. To start off things, I ran this simple code:

JavaScript

And the terminal command looks like this:

JavaScript

Edit: Corrected to this

JavaScript

Lua libraries are installed on my system (Linux), but the linker can’t find the definition for luaL_newstate(), despite the fact that I included the library in the command line:

JavaScript

And that happens with any Lua function. I don’t really know what went wrong, importing libraries in Linux was pretty straightforward up until now. This seems to be a problem with me not familiar with using libraries in my projects, but I couldn’t find very useful documentation. Thank you in advance.

Advertisement

Answer

-L option designates a folder where library files are kept; try g++ main.cpp -Llib -llua

Also wrap #include for Lua headers into extern "C":

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement