2

I am attempting to follow the besic guide given here on embedding lua into C. I copied the code verbatim into my own embed.c file and executed the exact compiler command listed:

cc -o embed embed.c \
            -I/usr/local/include \
            -L/usr/local/lib \
            -llua -llualib

I get the error:

embed.c:19:14: error: invalid storage class for function ‘openlualibs’

After which I moved the functions outside of main, compiled again, and got:

/usr/bin/ld: cannot find -llualib

I am at a loss for why I cannot compile this. lua is installed properly. has anyone else encountered these problems? If this is a bad tutorial, please feel free to simply direct me to a batter one.

2
  • The linker claims it has searched the paths you gave it and was unable to find the library in question. Is there, in fact, a file called liblualib.so or liblualib.a in /usr/local/lib? Commented Jul 30, 2012 at 19:20
  • @BrianCain no. there is in fact no liblualib.a or liblualib.so anywhere in /usr. any idea what I need to install? Commented Jul 30, 2012 at 19:22

2 Answers 2

5

On some Linux distributions you may need to install the lua-devel (or similar named) package, in order to get the proper header files and library symlinks required for compiling and linking projects against the package. If you do have a liblualib-<version>.so.<version>, for example liblualib-5.so.5.0, you may need to install the devel package.

Starting with lua 5.1, liblualib does not exist. Here is the release announcement: http://lua-users.org/lists/lua-l/2005-05/msg00186.html

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

4 Comments

I am using ArchLinux. I've searched for lua-devel in pacman and gotten no results
Debian-based distros usually call it X-dev (as opposed to X-devel in redhat-alikes). Not sure where Arch falls, but it seems worth a look under lua-dev.
Searching the package database for ArchLinux, it appears liblualib does not exist for Arch. Only liblua.so (in package lua) exists. I'll keep this answer around for posterity, in case someone else has a similar problem that may be solved by it.
And I don't see a reason for the downvote, +1 for compensating.
1

I've had somewhat similar problems when embedding Lua. What I found that works for me is linking the dynamic link library (dl) and the math library (m). The math library may not be necessary if you're not using the lmath standard library.

cc -o embed embed.c -I/usr/local/include -L/usr/local/lib -llua -lm -ldl

This, of course, assumes that /usr/local/ is where the Lua files are installed, which is probably true.

As for the tutorial you linked to, I think it may be very out of date. Besides liblualib no longer existing, there are individual functions to open each standard library. These are the luaopen_* functions. Here's the relevant 5.1 reference manual entry. (I assume you're using 5.1, since that seems to be the version available in the packages) As for a better tutorial, I suggest the Programming in Lua book. Unfortunately, it was written for Lua 5.0. It is still mostly relevant, but I suggest you look over the relevant sections of the 5.1 reference manual, too.

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.