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 Updated to NodeBB v4.3 + New Features

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 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";
    }
    
    aha_1980A 1 Reply Last reply
    0
    • ? A Former User

      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";
      }
      
      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on 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
      1
      • aha_1980A aha_1980

        @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 last edited by A Former User
        #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

        aha_1980A 1 Reply Last reply
        0
        • ? A Former User

          @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

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on 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
          0
          • aha_1980A aha_1980

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

            aha_1980A 1 Reply Last reply
            0
            • ? A Former User

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

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on 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
              0
              • aha_1980A aha_1980

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

                aha_1980A 1 Reply Last reply
                0
                • ? A Former User

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

                  aha_1980A Offline
                  aha_1980A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on 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
                  1
                  • aha_1980A aha_1980

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

                    • Login

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