Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. How to include the Lua library into my Qt project?
Forum Update on Monday, May 27th 2025

How to include the Lua library into my Qt project?

Scheduled Pinned Locked Moved Unsolved Language Bindings
9 Posts 2 Posters 2.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on 12 Oct 2019, 19:38 last edited by
    #1

    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";
    }
    
    A 1 Reply Last reply 12 Oct 2019, 19:42
    0
    • ? A Former User
      12 Oct 2019, 19:38

      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";
      }
      
      A Offline
      A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on 12 Oct 2019, 19:42 last edited by aha_1980
      #2

      @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.

      Qt has to stay free or it will die.

      ? 1 Reply Last reply 12 Oct 2019, 20:42
      1
      • A aha_1980
        12 Oct 2019, 19:42

        @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.

        ? Offline
        ? Offline
        A Former User
        wrote on 12 Oct 2019, 20:42 last edited by A Former User 10 Dec 2019, 20:44
        #3

        @aha_1980 thanks!

        It now tells me "extern_resources" is an invalid argument.

        The compiler I'm using is MinGW 730_64 (mingw32-make.exe).

        EDIT:
        Forgot one dash on the LIBS line.
        Now it tells me it cannot find lua53.lib

        A 1 Reply Last reply 13 Oct 2019, 06:05
        0
        • ? A Former User
          12 Oct 2019, 20:42

          @aha_1980 thanks!

          It now tells me "extern_resources" is an invalid argument.

          The compiler I'm using is MinGW 730_64 (mingw32-make.exe).

          EDIT:
          Forgot one dash on the LIBS line.
          Now it tells me it cannot find lua53.lib

          A Offline
          A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on 13 Oct 2019, 06:05 last edited by aha_1980
          #4

          @SnuggleKat

          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

          Qt has to stay free or it will die.

          ? 1 Reply Last reply 13 Oct 2019, 11:14
          0
          • A aha_1980
            13 Oct 2019, 06:05

            @SnuggleKat

            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

            ? Offline
            ? Offline
            A Former User
            wrote on 13 Oct 2019, 11:14 last edited by aha_1980
            #5

            @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..

            A 1 Reply Last reply 13 Oct 2019, 14:28
            0
            • ? A Former User
              13 Oct 2019, 11:14

              @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..

              A Offline
              A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on 13 Oct 2019, 14:28 last edited by aha_1980
              #6

              @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?

              Qt has to stay free or it will die.

              ? 1 Reply Last reply 13 Oct 2019, 18:22
              0
              • A aha_1980
                13 Oct 2019, 14:28

                @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?

                ? Offline
                ? Offline
                A Former User
                wrote on 13 Oct 2019, 18:22 last edited by
                #7

                @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.lib

                On the lua website you can also find the source code and compile the binaries yourself. I'm just unfamiliar with building makefiles on Windows..

                A 1 Reply Last reply 13 Oct 2019, 19:02
                0
                • ? A Former User
                  13 Oct 2019, 18:22

                  @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.lib

                  On the lua website you can also find the source code and compile the binaries yourself. I'm just unfamiliar with building makefiles on Windows..

                  A Offline
                  A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on 13 Oct 2019, 19:02 last edited by
                  #8

                  @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

                  Qt has to stay free or it will die.

                  ? 1 Reply Last reply 13 Oct 2019, 20:27
                  1
                  • A aha_1980
                    13 Oct 2019, 19:02

                    @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

                    ? Offline
                    ? Offline
                    A Former User
                    wrote on 13 Oct 2019, 20:27 last edited by
                    #9

                    @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

                    1 Reply Last reply
                    0

                    9/9

                    13 Oct 2019, 20:27

                    • Login

                    • Login or register to search.
                    9 out of 9
                    • First post
                      9/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved