How to include the Lua library into my Qt project?
-
Hello,
I've been developing a project where the user can run Lua scripts written in a textEdit.
I followed a tutorial on how to include it into my VS solution and it worked fine. However, with Qt it doesn't seem to be as easy as with VS.I get "undefined reference to" error messages at compile time.
Header file
#ifndef CHEATS_H #define CHEATS_H extern "C" { #include"extern_resources/include/lauxlib.h" #include"extern_resources/include/lua.h" #include"extern_resources/include/lualib.h" } #include<QDebug> //#ifdef _WIN32 #pragma comment(lib, "extern_resources/lua53.lib") //#endif class Cheats { public: Cheats(); ~Cheats(){ lua_close(L); } private: lua_State* L = luaL_newstate(); }; #endif // CHEATS_H
Cpp file
#include "cheats.h" Cheats::Cheats() { luaL_openlibs(L); qDebug() << "libs opened"; }
-
@SnuggleKat said in How to include the Lua library into my Qt project?:
extern_resources/lua53.lib
You need to specify the linker options in your .pro file.
Something like
LIBS += -L$$PWD/extern_resources -llua53
Btw, which compiler are you using for Qt? The library needs to match this compiler version exactly, otherwise it will not work.
Regards
Edit: changed
-llua53.lib
to-llua53
which is more universal. -
Ah, MinGW. So do you have the lua library compatible to MinGW and in the correct bitness (64bit)?
Can you show the contents of the external_resources directory?
Also, I've edited my post above to make it more general.
Regards
-
@aha_1980 it has both a 32 and 64-bit release. Got it from here where it says "get the binary".
I start doubting it's compatible with MinGW.. -
@SnuggleKat said in How to include the Lua library into my Qt project?:
Got it from here where it says "get the binary".
It does not show that to me, probably as I'm not on Windows.
Can you show the contents of the library folder?
Can you use the MSVC compiler?
-
@aha_1980 here's the direct link. If you scroll down you can find a list of all available binaries. I have the 5.3.5 one.
Oh, and this is what the extern_resources folder looks like:
include/lauxlib.h
include/lua.h
include/lua.hpp
include/luaconf.h
include/lualib.h
lua53.dll
lua53.libOn the lua website you can also find the source code and compile the binaries yourself. I'm just unfamiliar with building makefiles on Windows..
-
@SnuggleKat said in How to include the Lua library into my Qt project?:
lua53.lib
That seems to be a binary for MSVC, indeed.
On the lua website you can also find the source code and compile the binaries yourself.
That is one possibility. The other one is to find a binary package compatible to MinGW. And the third one is to use the MSVC compiler in Qt Creator.
Regards
-
@aha_1980 I will try compiling it myself since I'd like to stick with MinGW.
Just tried that but MinGW outputs the following:
0 [main] sh 1816 sync_with_child: child 12536(0x1E4) died before initializing with status code 0xC0000142
208 [main] sh 1816 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable
mingw32-make: *** [Makefile:55: mingw] Error 128