Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to add macro for the LIBS in the .PRO file
Forum Updated to NodeBB v4.3 + New Features

How to add macro for the LIBS in the .PRO file

Scheduled Pinned Locked Moved Unsolved General and Desktop
31 Posts 3 Posters 8.0k 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.
  • M Offline
    M Offline
    ManiRon
    wrote on 7 Sept 2018, 10:05 last edited by
    #1

    I am using two library one for windows and another for Linux. Now i want to define an macro for both of them such that while i run my application in windows i can add Windows Macro and vice versa.
    For example: DEFINES += "Windows="LIBS += -L$$PWD/release/ -ldata""
    DEFINES += "Linux="LIBS += -L$$PWD/release/ -lLinuxdata""

    LIBS += Windows

    Like this anything is possible

    R 1 Reply Last reply 7 Sept 2018, 10:14
    0
    • C Offline
      C Offline
      Cobra91151
      wrote on 7 Sept 2018, 10:13 last edited by
      #2

      Hi! You can add libs like this:

      unix {
         LIBS += -L"$$PWD/release/" -lLinuxdata
      }
      
      win32 {
         LIBS += -L"$$PWD/release/" -ldata
      }
      
      1 Reply Last reply
      2
      • M ManiRon
        7 Sept 2018, 10:05

        I am using two library one for windows and another for Linux. Now i want to define an macro for both of them such that while i run my application in windows i can add Windows Macro and vice versa.
        For example: DEFINES += "Windows="LIBS += -L$$PWD/release/ -ldata""
        DEFINES += "Linux="LIBS += -L$$PWD/release/ -lLinuxdata""

        LIBS += Windows

        Like this anything is possible

        R Offline
        R Offline
        Ratzz
        wrote on 7 Sept 2018, 10:14 last edited by Ratzz 9 Jul 2018, 10:17
        #3

        @ManiRon
        If you are adding lib via add Library from Qt Creator it gives option for different platforms. something like this.

        win32:CONFIG(release, debug|release): LIBS += -L$$PWD/Qwt_Plot/lib/ -lqwt
        else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/Qwt_Plot/lib/ -lqwtd
        else:unix:!macx: LIBS += -L$$PWD/Qwt_Plot/lib/ -lqwt
        

        alt text

        Or you can add the code manually in the .pro file

        --Alles ist gut.

        M 1 Reply Last reply 7 Sept 2018, 10:21
        3
        • R Ratzz
          7 Sept 2018, 10:14

          @ManiRon
          If you are adding lib via add Library from Qt Creator it gives option for different platforms. something like this.

          win32:CONFIG(release, debug|release): LIBS += -L$$PWD/Qwt_Plot/lib/ -lqwt
          else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/Qwt_Plot/lib/ -lqwtd
          else:unix:!macx: LIBS += -L$$PWD/Qwt_Plot/lib/ -lqwt
          

          alt text

          Or you can add the code manually in the .pro file

          M Offline
          M Offline
          ManiRon
          wrote on 7 Sept 2018, 10:21 last edited by
          #4

          @Ratzz i want to specify macro for this

          M 1 Reply Last reply 7 Sept 2018, 10:23
          0
          • M ManiRon
            7 Sept 2018, 10:21

            @Ratzz i want to specify macro for this

            M Offline
            M Offline
            ManiRon
            wrote on 7 Sept 2018, 10:23 last edited by ManiRon 9 Jul 2018, 10:23
            #5

            My point is i want to define macro for the both the library path and use only one by defining that macro to the LIBS +=. so that which ever i have defined in LIBS should be used .

            C 1 Reply Last reply 7 Sept 2018, 11:14
            0
            • M ManiRon
              7 Sept 2018, 10:23

              My point is i want to define macro for the both the library path and use only one by defining that macro to the LIBS +=. so that which ever i have defined in LIBS should be used .

              C Offline
              C Offline
              Cobra91151
              wrote on 7 Sept 2018, 11:14 last edited by Cobra91151 9 Jul 2018, 11:19
              #6

              @ManiRon

              Why do you want to create your macro if it already done by Qt?

              Code:

              unix {
                 LIBS += -L"$$PWD/release/" -lLinuxdata
              }
              
              win32 {
                 LIBS += -L"$$PWD/release/" -ldata
              }
              

              unix will be used on Unix systems, it includes the Linux.
              win32 will be used on Windows systems.

              You can define your macro, for example:

              DEFINES += MY_MACRO=true

              I can only think that you want something like that:

              DEFINES += MY_LIB_PATH="$$PWD/release/"

              So you can define the one path to libraries and use it:

              unix {
                 LIBS += -L"$$MY_LIB_PATH" -lLinuxdata
              }
              
              win32 {
                 LIBS += -L"$$MY_LIB_PATH" -ldata
              }
              

              But you still need unix/win32 checks.

              M 2 Replies Last reply 7 Sept 2018, 12:19
              1
              • C Cobra91151
                7 Sept 2018, 11:14

                @ManiRon

                Why do you want to create your macro if it already done by Qt?

                Code:

                unix {
                   LIBS += -L"$$PWD/release/" -lLinuxdata
                }
                
                win32 {
                   LIBS += -L"$$PWD/release/" -ldata
                }
                

                unix will be used on Unix systems, it includes the Linux.
                win32 will be used on Windows systems.

                You can define your macro, for example:

                DEFINES += MY_MACRO=true

                I can only think that you want something like that:

                DEFINES += MY_LIB_PATH="$$PWD/release/"

                So you can define the one path to libraries and use it:

                unix {
                   LIBS += -L"$$MY_LIB_PATH" -lLinuxdata
                }
                
                win32 {
                   LIBS += -L"$$MY_LIB_PATH" -ldata
                }
                

                But you still need unix/win32 checks.

                M Offline
                M Offline
                ManiRon
                wrote on 7 Sept 2018, 12:19 last edited by ManiRon 9 Jul 2018, 12:19
                #7

                @Cobra91151

                For xenomai and fedora what should i define
                for example:

                for linux : unix, Windows: win32, similarly for Fedora : ?,
                and Xenomai : ?

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Cobra91151
                  wrote on 7 Sept 2018, 12:27 last edited by Cobra91151 9 Jul 2018, 12:29
                  #8

                  @ManiRon

                  For Xenomai and Fedora should work unix and for Windows - win32.

                  From the Qt documentation:

                  Platform Scope Values
                  In addition to the win32, macx, and unix values used in many scope conditions, various other built-in platform and compiler-specific values can be tested with scopes. These are based on platform specifications provided in Qt's mkspecs directory. For example, the following lines from a project file show the current specification in use and test for the linux-g++ specification:
                  
                  message($$QMAKESPEC)
                  
                  linux-g++ {
                      message(Linux)
                  }
                  You can test for any other platform-compiler combination as long as a specification exists for it in the mkspecs directory.
                  
                  The scope unix is true for the Symbian platform.
                  

                  Official Qt docs: http://doc.qt.io/archives/qt-4.8/qmake-advanced-usage.html

                  1 Reply Last reply
                  2
                  • C Cobra91151
                    7 Sept 2018, 11:14

                    @ManiRon

                    Why do you want to create your macro if it already done by Qt?

                    Code:

                    unix {
                       LIBS += -L"$$PWD/release/" -lLinuxdata
                    }
                    
                    win32 {
                       LIBS += -L"$$PWD/release/" -ldata
                    }
                    

                    unix will be used on Unix systems, it includes the Linux.
                    win32 will be used on Windows systems.

                    You can define your macro, for example:

                    DEFINES += MY_MACRO=true

                    I can only think that you want something like that:

                    DEFINES += MY_LIB_PATH="$$PWD/release/"

                    So you can define the one path to libraries and use it:

                    unix {
                       LIBS += -L"$$MY_LIB_PATH" -lLinuxdata
                    }
                    
                    win32 {
                       LIBS += -L"$$MY_LIB_PATH" -ldata
                    }
                    

                    But you still need unix/win32 checks.

                    M Offline
                    M Offline
                    ManiRon
                    wrote on 10 Sept 2018, 06:40 last edited by ManiRon 9 Oct 2018, 06:41
                    #9

                    @Cobra91151 Sir i am trying to add

                    uinx{
                    LIBS+= -L$$PWD/.../lib/linus/-lData
                    LIBS+= -L$$PWD/.../lib/Xenomai/-lData1 -lrtdm -lrt -lxenomai
                    }

                    I am adding the linux and xenomai library and trying to compile . but it throws error. As it detects the linux library and it couldnt find the xenomai library it throws error.
                    My question is i want to define all my library and based on the platform or OS i am running it should detect its particular library.
                    For example : linux, xenomai, windiows. These are the platforms i am running the application. Why i ask this is because every time i have to add the corresponding library and compile it and the run the application . So is there any solution for this?

                    C 1 Reply Last reply 10 Sept 2018, 08:30
                    0
                    • M ManiRon
                      10 Sept 2018, 06:40

                      @Cobra91151 Sir i am trying to add

                      uinx{
                      LIBS+= -L$$PWD/.../lib/linus/-lData
                      LIBS+= -L$$PWD/.../lib/Xenomai/-lData1 -lrtdm -lrt -lxenomai
                      }

                      I am adding the linux and xenomai library and trying to compile . but it throws error. As it detects the linux library and it couldnt find the xenomai library it throws error.
                      My question is i want to define all my library and based on the platform or OS i am running it should detect its particular library.
                      For example : linux, xenomai, windiows. These are the platforms i am running the application. Why i ask this is because every time i have to add the corresponding library and compile it and the run the application . So is there any solution for this?

                      C Offline
                      C Offline
                      Cobra91151
                      wrote on 10 Sept 2018, 08:30 last edited by Cobra91151 9 Oct 2018, 08:34
                      #10

                      @ManiRon

                      @ManiRon said in How to add macro for the LIBS in the .PRO file:

                      @Cobra91151 Sir i am trying to add

                      uinx{
                      LIBS+= -L$$PWD/.../lib/linus/-lData
                      LIBS+= -L$$PWD/.../lib/Xenomai/-lData1 -lrtdm -lrt -lxenomai
                      }

                      I am adding the linux and xenomai library and trying to compile . but it throws error. As it detects the linux library and it couldnt find the xenomai library it throws error.
                      My question is i want to define all my library and based on the platform or OS i am running it should detect its particular library.
                      For example : linux, xenomai, windiows. These are the platforms i am running the application. Why i ask this is because every time i have to add the corresponding library and compile it and the run the application . So is there any solution for this?

                      First all of all, you typed uinx, it should be unix, so the errors might be with it. Secondly, Xenomai is built with the Linux kernel, so in your case it will load both libs.

                      So, you have to be more specific with your checks, read my post above:
                      In addition to the win32, macx, and unix values used in many scope conditions, various other built-in platform and compiler-specific values...

                      M 1 Reply Last reply 10 Sept 2018, 08:58
                      2
                      • C Cobra91151
                        10 Sept 2018, 08:30

                        @ManiRon

                        @ManiRon said in How to add macro for the LIBS in the .PRO file:

                        @Cobra91151 Sir i am trying to add

                        uinx{
                        LIBS+= -L$$PWD/.../lib/linus/-lData
                        LIBS+= -L$$PWD/.../lib/Xenomai/-lData1 -lrtdm -lrt -lxenomai
                        }

                        I am adding the linux and xenomai library and trying to compile . but it throws error. As it detects the linux library and it couldnt find the xenomai library it throws error.
                        My question is i want to define all my library and based on the platform or OS i am running it should detect its particular library.
                        For example : linux, xenomai, windiows. These are the platforms i am running the application. Why i ask this is because every time i have to add the corresponding library and compile it and the run the application . So is there any solution for this?

                        First all of all, you typed uinx, it should be unix, so the errors might be with it. Secondly, Xenomai is built with the Linux kernel, so in your case it will load both libs.

                        So, you have to be more specific with your checks, read my post above:
                        In addition to the win32, macx, and unix values used in many scope conditions, various other built-in platform and compiler-specific values...

                        M Offline
                        M Offline
                        ManiRon
                        wrote on 10 Sept 2018, 08:58 last edited by ManiRon 9 Oct 2018, 09:01
                        #11

                        @Cobra91151

                        for xenomai what should i do sir?

                        While giving unix it runs the library for linux and if i want to do the same for xenomai what should i specify?

                        And i want to know where this message($$QMAKESPEC) will be displayed?

                        C 1 Reply Last reply 10 Sept 2018, 09:09
                        0
                        • M ManiRon
                          10 Sept 2018, 08:58

                          @Cobra91151

                          for xenomai what should i do sir?

                          While giving unix it runs the library for linux and if i want to do the same for xenomai what should i specify?

                          And i want to know where this message($$QMAKESPEC) will be displayed?

                          C Offline
                          C Offline
                          Cobra91151
                          wrote on 10 Sept 2018, 09:09 last edited by Cobra91151 9 Oct 2018, 09:10
                          #12

                          @ManiRon

                          Xenomai should have something, I use Windows OS, so I don't know exactly. message($$QMAKESPEC) will be displayed in the General Messages in the Qt Creator. Check the output message($$QMAKESPEC) and reply. I will try to help you.

                          M 1 Reply Last reply 10 Sept 2018, 09:13
                          2
                          • C Cobra91151
                            10 Sept 2018, 09:09

                            @ManiRon

                            Xenomai should have something, I use Windows OS, so I don't know exactly. message($$QMAKESPEC) will be displayed in the General Messages in the Qt Creator. Check the output message($$QMAKESPEC) and reply. I will try to help you.

                            M Offline
                            M Offline
                            ManiRon
                            wrote on 10 Sept 2018, 09:13 last edited by
                            #13

                            @Cobra91151 Ok sir

                            M 1 Reply Last reply 10 Sept 2018, 09:13
                            0
                            • M ManiRon
                              10 Sept 2018, 09:13

                              @Cobra91151 Ok sir

                              M Offline
                              M Offline
                              ManiRon
                              wrote on 10 Sept 2018, 09:13 last edited by
                              #14

                              @ManiRon
                              I tried with windows it returned win32-g++ ?

                              C 1 Reply Last reply 10 Sept 2018, 09:36
                              0
                              • M ManiRon
                                10 Sept 2018, 09:13

                                @ManiRon
                                I tried with windows it returned win32-g++ ?

                                C Offline
                                C Offline
                                Cobra91151
                                wrote on 10 Sept 2018, 09:36 last edited by
                                #15

                                @ManiRon said in How to add macro for the LIBS in the .PRO file:

                                @ManiRon
                                I tried with windows it returned win32-g++ ?

                                Ok. So you can use it on Windows, but you have to check it with Xenomai. By the way, win32-g++ means that you use MinGW compiler. Reply when you get the output for Xenomai.

                                M 3 Replies Last reply 10 Sept 2018, 10:08
                                0
                                • C Cobra91151
                                  10 Sept 2018, 09:36

                                  @ManiRon said in How to add macro for the LIBS in the .PRO file:

                                  @ManiRon
                                  I tried with windows it returned win32-g++ ?

                                  Ok. So you can use it on Windows, but you have to check it with Xenomai. By the way, win32-g++ means that you use MinGW compiler. Reply when you get the output for Xenomai.

                                  M Offline
                                  M Offline
                                  ManiRon
                                  wrote on 10 Sept 2018, 10:08 last edited by
                                  #16

                                  @Cobra91151 ok Sir

                                  1 Reply Last reply
                                  0
                                  • C Cobra91151
                                    10 Sept 2018, 09:36

                                    @ManiRon said in How to add macro for the LIBS in the .PRO file:

                                    @ManiRon
                                    I tried with windows it returned win32-g++ ?

                                    Ok. So you can use it on Windows, but you have to check it with Xenomai. By the way, win32-g++ means that you use MinGW compiler. Reply when you get the output for Xenomai.

                                    M Offline
                                    M Offline
                                    ManiRon
                                    wrote on 10 Sept 2018, 12:04 last edited by
                                    #17

                                    @Cobra91151

                                    I have a doubt?

                                    C 1 Reply Last reply 10 Sept 2018, 12:15
                                    0
                                    • C Cobra91151
                                      10 Sept 2018, 09:36

                                      @ManiRon said in How to add macro for the LIBS in the .PRO file:

                                      @ManiRon
                                      I tried with windows it returned win32-g++ ?

                                      Ok. So you can use it on Windows, but you have to check it with Xenomai. By the way, win32-g++ means that you use MinGW compiler. Reply when you get the output for Xenomai.

                                      M Offline
                                      M Offline
                                      ManiRon
                                      wrote on 10 Sept 2018, 12:08 last edited by
                                      #18

                                      @Cobra91151

                                      i generated a code in .pro file as

                                      win32-g++{
                                      LIBS += path
                                      }
                                      linux-g++ {
                                      LIBS += path
                                      }

                                      i am creating a bundle with the .exe and the required files and if i run this in a PC which does not have QT will it work

                                      C 1 Reply Last reply 10 Sept 2018, 12:39
                                      0
                                      • M ManiRon
                                        10 Sept 2018, 12:04

                                        @Cobra91151

                                        I have a doubt?

                                        C Offline
                                        C Offline
                                        Cobra91151
                                        wrote on 10 Sept 2018, 12:15 last edited by Cobra91151 9 Oct 2018, 12:24
                                        #19

                                        @ManiRon said in How to add macro for the LIBS in the .PRO file:

                                        @Cobra91151

                                        I have a doubt?

                                        @ManiRon said in How to add macro for the LIBS in the .PRO file:

                                        @Cobra91151

                                        i generated a code in .pro file as

                                        win32-g++{
                                        LIBS += path
                                        }
                                        linux-g++ {
                                        LIBS += path
                                        }

                                        i am creating a bundle with the .exe and the required files and if i run this in a PC which does not have QT will it work

                                        You have doubt about what? Is linux-g++ scope condition from Xenomai output?

                                        Also, you have to provide all the necessary Qt libs if the Qt is not static (on the PC which does not have Qt) otherwise it wont work. For example, for Windows, you have to run windeployqt.exe to get Qt shared libs.

                                        Official docs about the deployment for Windows: http://doc.qt.io/qt-5/windows-deployment.html

                                        M 1 Reply Last reply 11 Sept 2018, 03:29
                                        0
                                        • M ManiRon
                                          10 Sept 2018, 12:08

                                          @Cobra91151

                                          i generated a code in .pro file as

                                          win32-g++{
                                          LIBS += path
                                          }
                                          linux-g++ {
                                          LIBS += path
                                          }

                                          i am creating a bundle with the .exe and the required files and if i run this in a PC which does not have QT will it work

                                          C Offline
                                          C Offline
                                          Cobra91151
                                          wrote on 10 Sept 2018, 12:39 last edited by Cobra91151 9 Oct 2018, 13:08
                                          #20

                                          @ManiRon

                                          So, you should have something like this in the pro file:

                                          TARGET = TestApp #Your executable filename without the extension
                                          
                                          win32-g++ {
                                              LIBS += path
                                              QMAKE_POST_LINK = $$(QTDIR)/bin/windeployqt.exe $$shell_quote($$DESTDIR/$$shell_quote($$TARGET).exe) --no-compiler-runtime
                                          }
                                          

                                          This will add one more build step to the project, but it will help to deploy all the necessary Qt libs. By the way, it will work only for Windows deployment and shared libs Qt version.

                                          Linux deployment Qt docs here: http://doc.qt.io/qt-5/linux-deployment.html

                                          1 Reply Last reply
                                          0

                                          3/31

                                          7 Sept 2018, 10:14

                                          topic:navigator.unread, 28
                                          • Login

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