Page 1 of 2

Lua Binding Won't Compile with G++ --HELP!

Posted: Thu May 10, 2012 1:29 pm
by OmenFelix
Hey guys. I've recently been trying to get my first Lua binding to work with C++ and well I can't get it to compile.
Here's how I'm compiling it:

Code: Select all

gcc -o luac invoke.cpp -llua51 -llua5.1 -I "C:\Program Files (x86)\Lua\5.1\include" -L "C:\Program Files (x86)\Lua\5.1\lib"
And here's the errors I get:
C:\Users\Admin\AppData\Local\Temp\ccmDm0z8.o:invoke.cpp:(.text+0xf): undefined r
eference to `luaL_newstate()'
C:\Users\Admin\AppData\Local\Temp\ccmDm0z8.o:invoke.cpp:(.text+0x1f): undefined
reference to `luaL_openlibs(lua_State*)'
C:\Users\Admin\AppData\Local\Temp\ccmDm0z8.o:invoke.cpp:(.text+0x33): undefined
reference to `luaL_loadfile(lua_State*, char const*)'
C:\Users\Admin\AppData\Local\Temp\ccmDm0z8.o:invoke.cpp:(.text+0x5b): undefined
reference to `lua_pcall(lua_State*, int, int, int)'
C:\Users\Admin\AppData\Local\Temp\ccmDm0z8.o:invoke.cpp:(.text+0x85): undefined
reference to `lua_tolstring(lua_State*, int, unsigned int*)'
C:\Users\Admin\AppData\Local\Temp\ccmDm0z8.o:invoke.cpp:(.text+0xbb): undefined
reference to `lua_getfield(lua_State*, int, char const*)'
C:\Users\Admin\AppData\Local\Temp\ccmDm0z8.o:invoke.cpp:(.text+0xcf): undefined
reference to `lua_type(lua_State*, int)'
C:\Users\Admin\AppData\Local\Temp\ccmDm0z8.o:invoke.cpp:(.text+0xed): undefined
reference to `lua_settop(lua_State*, int)'
C:\Users\Admin\AppData\Local\Temp\ccmDm0z8.o:invoke.cpp:(.text+0x115): undefined
reference to `lua_pushnumber(lua_State*, double)'
C:\Users\Admin\AppData\Local\Temp\ccmDm0z8.o:invoke.cpp:(.text+0x133): undefined
reference to `lua_pushnumber(lua_State*, double)'
C:\Users\Admin\AppData\Local\Temp\ccmDm0z8.o:invoke.cpp:(.text+0x157): undefined
reference to `lua_pcall(lua_State*, int, int, int)'
C:\Users\Admin\AppData\Local\Temp\ccmDm0z8.o:invoke.cpp:(.text+0x17c): undefined
reference to `lua_tolstring(lua_State*, int, unsigned int*)'
C:\Users\Admin\AppData\Local\Temp\ccmDm0z8.o:invoke.cpp:(.text+0x1aa): undefined
reference to `lua_isnumber(lua_State*, int)'
C:\Users\Admin\AppData\Local\Temp\ccmDm0z8.o:invoke.cpp:(.text+0x1da): undefined
reference to `lua_tonumber(lua_State*, int)'
C:\Users\Admin\AppData\Local\Temp\ccmDm0z8.o:invoke.cpp:(.text+0x20e): undefined
reference to `lua_settop(lua_State*, int)'
C:\Users\Admin\AppData\Local\Temp\ccmDm0z8.o:invoke.cpp:(.text+0x21a): undefined
reference to `lua_close(lua_State*)'
collect2: ld returned 1 exit status
What do I have to do to get it to compile?

Re: Lua Binding Won't Compile with G++ --HELP!

Posted: Thu May 10, 2012 1:38 pm
by short
Undefined references are usually a sign the linker can't find the code your calling. I've never used lua, but make sure your linking all the libraries.

Re: Lua Binding Won't Compile with G++ --HELP!

Posted: Thu May 10, 2012 2:34 pm
by OmenFelix
*REMOVED*

Re: Lua Binding Won't Compile with G++ --HELP!

Posted: Thu May 10, 2012 3:11 pm
by qpHalcy0n
Way to be a dick, asshole.

Unless you're willing to work with us to find a possible solution to the problem, don't ask the question.

....."No offense"

Re: Lua Binding Won't Compile with G++ --HELP!

Posted: Thu May 10, 2012 3:16 pm
by OmenFelix
qpHalcy0n wrote:Way to be a dick, asshole.

Unless you're willing to work with us to find a possible solution to the problem, don't ask the question.

....."No offense"
I knew I was being 'dickish', but it's the truth. ;)

I'm sorry short. :P

Oh and btw Halcy, it's Marc, the guy you taught how to use VC++ a year ago. :P

Re: Lua Binding Won't Compile with G++ --HELP!

Posted: Thu May 10, 2012 4:05 pm
by qpHalcy0n
I'm sorry, I simply don't remember you. I talk to a lot of people. Clearly I didn't verse you on the finer points of tactful behaviour.......

Re: Lua Binding Won't Compile with G++ --HELP!

Posted: Thu May 10, 2012 4:17 pm
by OmenFelix
qpHalcy0n wrote:I'm sorry, I simply don't remember you. I talk to a lot of people. Clearly I didn't verse you on the finer points of tactful behaviour.......
I tend not to follow many social protocols, including that one, but I guess I'll try to in my future endeavours.

Re: Lua Binding Won't Compile with G++ --HELP!

Posted: Thu May 10, 2012 5:52 pm
by dandymcgee
OmenFelix wrote:I tend not to follow many social protocols, including that one, but I guess I'll try to in my future endeavours.
I recommend you start if you expect any assistance in the future. I doubt I'm the only one who is going to ignore people who make such childish remarks to someone genuinely trying to help.

Re: Lua Binding Won't Compile with G++ --HELP!

Posted: Thu May 10, 2012 5:56 pm
by OmenFelix
dandymcgee wrote:
OmenFelix wrote:I tend not to follow many social protocols, including that one, but I guess I'll try to in my future endeavours.
I recommend you start if you expect any assistance in the future. I doubt I'm the only one who is going to ignore people who make such childish remarks to someone genuinely trying to help.
I will. :)

Re: Lua Binding Won't Compile with G++ --HELP!

Posted: Thu May 10, 2012 7:44 pm
by short
LOL why did you take down what you posted?

I didn't get to see it..........

:nono:

Re: Lua Binding Won't Compile with G++ --HELP!

Posted: Fri May 11, 2012 1:52 am
by OmenFelix
short wrote:LOL why did you take down what you posted?

I didn't get to see it..........

:nono:
That's a good thing. :P Now I have a chance to redeem myself. :P

Anyway what I was saying was that I've linked to all the libraries in the Lua installation but people keep making reference to a libDL of which I've built and tried to get working but I get the same errors.

Re: Lua Binding Won't Compile with G++ --HELP!

Posted: Sun May 13, 2012 8:17 pm
by bbguimaraes
Are you including lua.h instead of lua.hpp?

Re: Lua Binding Won't Compile with G++ --HELP!

Posted: Mon May 14, 2012 9:49 am
by OmenFelix
bbguimaraes wrote:Are you including lua.h instead of lua.hpp?
GENIUS!!! <3 :worship:

Re: Lua Binding Won't Compile with G++ --HELP!

Posted: Mon May 14, 2012 2:38 pm
by bbguimaraes
Glad to help. The .hpp file works on c and c++. Actually, it's just a wrapper, like the c* file from the c++ standard library (cstring, stype, cstdio, etc). You can check its contents. On my system:

Code: Select all

bruno@bruno-notebook:~$ cat /usr/include/lua5.2/lua.hpp
// lua.hpp
// Lua header files for C++
// <<extern "C">> not supplied automatically because Lua also compiles as C++

extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
I also noticed you are using gcc instead of g++ on the command line. I hope you know the difference.

Re: Lua Binding Won't Compile with G++ --HELP!

Posted: Fri May 18, 2012 1:54 am
by OmenFelix
bbguimaraes wrote:Glad to help. The .hpp file works on c and c++. Actually, it's just a wrapper, like the c* file from the c++ standard library (cstring, stype, cstdio, etc). You can check its contents. On my system:

Code: Select all

bruno@bruno-notebook:~$ cat /usr/include/lua5.2/lua.hpp
// lua.hpp
// Lua header files for C++
// <<extern "C">> not supplied automatically because Lua also compiles as C++

extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
I also noticed you are using gcc instead of g++ on the command line. I hope you know the difference.
Ofcourse I know the difference, lol. Just a typo. I use G++ now. :P