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

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
OmenFelix
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 59
Joined: Fri May 04, 2012 1:42 pm
Current Project: Arcadian Descent(C++, SDL, KOS)
Favorite Gaming Platforms: PS2, PC, XBOX, NDS
Programming Language of Choice: C/C++

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

Post 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?
Why not check out my game-development forum at: http://f1rel0ck.netai.net
Or my 2D RPG at: https://www.facebook.com/pages/Arcadian ... 6873806531
Image
Image
Image
User avatar
short
ES Beta Backer
ES Beta Backer
Posts: 548
Joined: Thu Apr 30, 2009 2:22 am
Current Project: c++, c
Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
Programming Language of Choice: c, c++
Location: Oregon, US

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

Post 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.
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
User avatar
OmenFelix
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 59
Joined: Fri May 04, 2012 1:42 pm
Current Project: Arcadian Descent(C++, SDL, KOS)
Favorite Gaming Platforms: PS2, PC, XBOX, NDS
Programming Language of Choice: C/C++

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

Post by OmenFelix »

*REMOVED*
Last edited by OmenFelix on Thu May 10, 2012 3:33 pm, edited 1 time in total.
Why not check out my game-development forum at: http://f1rel0ck.netai.net
Or my 2D RPG at: https://www.facebook.com/pages/Arcadian ... 6873806531
Image
Image
Image
qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

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

Post 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"
User avatar
OmenFelix
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 59
Joined: Fri May 04, 2012 1:42 pm
Current Project: Arcadian Descent(C++, SDL, KOS)
Favorite Gaming Platforms: PS2, PC, XBOX, NDS
Programming Language of Choice: C/C++

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

Post 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
Why not check out my game-development forum at: http://f1rel0ck.netai.net
Or my 2D RPG at: https://www.facebook.com/pages/Arcadian ... 6873806531
Image
Image
Image
qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

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

Post 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.......
User avatar
OmenFelix
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 59
Joined: Fri May 04, 2012 1:42 pm
Current Project: Arcadian Descent(C++, SDL, KOS)
Favorite Gaming Platforms: PS2, PC, XBOX, NDS
Programming Language of Choice: C/C++

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

Post 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.
Why not check out my game-development forum at: http://f1rel0ck.netai.net
Or my 2D RPG at: https://www.facebook.com/pages/Arcadian ... 6873806531
Image
Image
Image
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

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

Post 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.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
OmenFelix
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 59
Joined: Fri May 04, 2012 1:42 pm
Current Project: Arcadian Descent(C++, SDL, KOS)
Favorite Gaming Platforms: PS2, PC, XBOX, NDS
Programming Language of Choice: C/C++

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

Post 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. :)
Why not check out my game-development forum at: http://f1rel0ck.netai.net
Or my 2D RPG at: https://www.facebook.com/pages/Arcadian ... 6873806531
Image
Image
Image
User avatar
short
ES Beta Backer
ES Beta Backer
Posts: 548
Joined: Thu Apr 30, 2009 2:22 am
Current Project: c++, c
Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
Programming Language of Choice: c, c++
Location: Oregon, US

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

Post by short »

LOL why did you take down what you posted?

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

:nono:
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
User avatar
OmenFelix
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 59
Joined: Fri May 04, 2012 1:42 pm
Current Project: Arcadian Descent(C++, SDL, KOS)
Favorite Gaming Platforms: PS2, PC, XBOX, NDS
Programming Language of Choice: C/C++

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

Post 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.
Why not check out my game-development forum at: http://f1rel0ck.netai.net
Or my 2D RPG at: https://www.facebook.com/pages/Arcadian ... 6873806531
Image
Image
Image
User avatar
bbguimaraes
Chaos Rift Junior
Chaos Rift Junior
Posts: 294
Joined: Wed Apr 11, 2012 4:34 pm
Programming Language of Choice: c++
Location: Brazil
Contact:

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

Post by bbguimaraes »

Are you including lua.h instead of lua.hpp?
User avatar
OmenFelix
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 59
Joined: Fri May 04, 2012 1:42 pm
Current Project: Arcadian Descent(C++, SDL, KOS)
Favorite Gaming Platforms: PS2, PC, XBOX, NDS
Programming Language of Choice: C/C++

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

Post by OmenFelix »

bbguimaraes wrote:Are you including lua.h instead of lua.hpp?
GENIUS!!! <3 :worship:
Why not check out my game-development forum at: http://f1rel0ck.netai.net
Or my 2D RPG at: https://www.facebook.com/pages/Arcadian ... 6873806531
Image
Image
Image
User avatar
bbguimaraes
Chaos Rift Junior
Chaos Rift Junior
Posts: 294
Joined: Wed Apr 11, 2012 4:34 pm
Programming Language of Choice: c++
Location: Brazil
Contact:

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

Post 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.
User avatar
OmenFelix
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 59
Joined: Fri May 04, 2012 1:42 pm
Current Project: Arcadian Descent(C++, SDL, KOS)
Favorite Gaming Platforms: PS2, PC, XBOX, NDS
Programming Language of Choice: C/C++

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

Post 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
Why not check out my game-development forum at: http://f1rel0ck.netai.net
Or my 2D RPG at: https://www.facebook.com/pages/Arcadian ... 6873806531
Image
Image
Image
Post Reply