• Announcement: Lua.org now officially recommends this forum as a meeting place for the Lua community

Embedding Lua in C/C++ (1 Viewer)

I'm following @stetre's amazing guide (link to guide) on how to embed Lua in C/C++
  • Lua version: 5.3
  • Operating system: Ubuntu 20.04 LTS
These are the additional steps I had to take to get it to work:

Note: I'm a complete beginner, and it may be obvious to more experienced Lua developers, but I'm posting some of the additional steps I had to take just in case others experience the same problem.

I got
Code:
main.c:2:10: fatal error: lua.h: No such file or directory
    2 | #include <lua.h>
      |          ^~~~~~~
compilation terminated.
when I tried to compile the program with
Bash:
cc -o myapp main.c -llua -lm -ldl

The solution was to install liblua5.3-dev (apt-get install liblua5.3-dev) and specify the Lua version when including the headers like this:
C:
#include <lua5.3/lua.h>
#include <lua5.3/lualib.h>
#include <lua5.3/lauxlib.h>

Then I got another error:
Code:
/usr/bin/ld: cannot find -llua
collect2: error: ld returned 1 exit status

Same problem, I had to add the version explicitly:
Bash:
cc -o myapp main.c -llua5.3 -lm -ldl

It compiled and I was able to run the script.
 

dinsdale247

Moderator
Staff member
Community Patron
Creator of WinLua
Joined
Nov 17, 2020
Messages
91
Reaction score
32
Location
Victoria BC
Website
winlua.net
Hi, check out Sol3. It's an amazing binging library for Lua/C++. Cross platform.

I have two articles on using it on Windows, but the code would be the same:


Cheers.
 
Top