1

I'm trying to compile a simple example of C code that includes Lua(5.2) libraries. I'm using the following command:

gcc graph.c -o graph -I/usr/local/include -L/usr/local/lib -llua

And getting the following errors:

    /usr/local/lib/liblua.a(lobject.o): In function `luaO_arith':
    lobject.c:(.text+0x15c): undefined reference to `floor'
    lobject.c:(.text+0x111): undefined reference to `pow'
    /usr/local/lib/liblua.a(lvm.o): In function `luaV_execute':
    lvm.c:(.text+0x24e9): undefined reference to `floor'
    lvm.c:(.text+0x25fe): undefined reference to `pow'
   ...

Looks like the math library is not linked, but not sure how to fix it... Any suggestions? I installed Lua following instructions from the Readme with make linux and install linux (have Ubuntu 12.04). Thanks!

Ola M
  • 1,298
  • 3
  • 12
  • 27
  • Yes, you're right. I added -lm and -ldl and it compiled. Sorry for duplicate... thought it is something specific to the Lua library. Thank you. – Ola M Mar 23 '13 at 21:42
  • @OlaM It's worth reading the error message before posting. If you had read it attentively, you would have quickly found out that this has nothing to do with Lua. –  Mar 23 '13 at 21:44

1 Answers1

1

Very simple: you just need to add -lm to the end of the line.

(The man pages for all the functions that require it will mention this.)

teppic
  • 8,039
  • 2
  • 24
  • 37