Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved qt qmake conditional libs based on platform

    General and Desktop
    5
    12
    3008
    Loading More Posts
    • 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.
    • mrjj
      mrjj Lifetime Qt Champion last edited by

      Hi
      in .pro file I have

      win32
      {
      LIBS += -lole32
      }

      and in linux it still wants to add that lib?
      So syntax is incorrect or wont work for LIBS ?

      1 Reply Last reply Reply Quote 0
      • M
        mostefa last edited by

        Actually the syntax is incorrect:

        when adding conditional libs you have to indicate the name of the system where the lib will be needed, for example:

        win32: LIBS += -lole32
        else:unix: LIBS += -lole32

        1 Reply Last reply Reply Quote 1
        • mrjj
          mrjj Lifetime Qt Champion last edited by

          so this syntax
          win32
          {

          }
          only works for includes / files?
          win32 {
          SOURCES += paintwidget_win.cpp
          }

          1 Reply Last reply Reply Quote 0
          • M
            mostefa last edited by

            No for me the problem is not from the syntax,

            the problem is that you specify only LIBS for win32 system,

            you need to specify the LIBS for unix too,

            Hope this can help!

            1 Reply Last reply Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              Hi,

              it's because of the line return. It should be

              win32 { #<< start of scope
                  LIBS += -lole32
              }
              

              The scope of win32 starts on the line you write it. So if you add a line return, the content of your brackets fall in the global scope.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              mrjj 1 Reply Last reply Reply Quote 1
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                @mostefa No it's not the problem at all. It's just a syntax error. There's no need to specify everything for all platforms.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply Reply Quote 0
                • mrjj
                  mrjj Lifetime Qt Champion @SGaist last edited by mrjj

                  @SGaist
                  Oh, that is sneaky.
                  now I understand.
                  just so used to
                  {
                  }
                  being a scope that the idea never cross my mind :)
                  so I made a nameless global scope ?

                  1 Reply Last reply Reply Quote 0
                  • M
                    mostefa last edited by

                    @SGaist ,

                    I know that we can write : LIBS += -lole32

                    But if we specify that win32: LIBS += -lole32

                    don't we need to specify it to linux ? thank's in advance,

                    jsulm 1 Reply Last reply Reply Quote 0
                    • jsulm
                      jsulm Lifetime Qt Champion @mostefa last edited by

                      @mostefa ole32 is a Windows specific library, as far as I know there is no such library for Linux

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply Reply Quote 0
                      • mrjj
                        mrjj Lifetime Qt Champion last edited by

                        well actually I ended up with
                        win32: LIBS += -lole32
                        else:unix: LIBS += -luuid

                        but it was just me not understanding the real syntax with
                        win32 {
                        }
                        as I did
                        win32
                        {
                        }
                        which is not the same. :)

                        1 Reply Last reply Reply Quote 0
                        • SGaist
                          SGaist Lifetime Qt Champion last edited by

                          @mostefa What you put in your scope depends on what you need. In this case it's a Windows only library that has no equivalent on Linux so no.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply Reply Quote 0
                          • Hamed.Masafi
                            Hamed.Masafi last edited by

                            Target and arch selector in qmake (I have used this in my project):

                            win32:{
                                contains(QMAKE_TARGET.arch, x86_64):{
                                    PLATFORM = "win-64"
                                }else{
                                    PLATFORM = "win-32"
                                }
                            }else{
                            
                                BITSIZE = $$system(getconf LONG_BIT)
                                if (contains(BITSIZE, 64)) {
                                    linux*: PLATFORM = "linux-64"
                                    macx*: PLATFORM = "mac-64"
                                }
                                if (contains(BITSIZE, 32)) {
                                    linux*: PLATFORM = "linux-32"
                                    macx*: PLATFORM = "mac-32"
                                }
                                android: PLATFORM = "android"
                                ios: PLATFORM = "ios"
                            }
                            
                            #include pri file based on platform
                            include(myproj-$${PLATFORM}.pri)
                            

                            Remote object sharing (OO RPC)
                            http://forum.qt.io/topic/60680/remote-object-sharing-oo-rpc-solved

                            Advanced, Powerful and easy to use ORM for Qt5
                            https://forum.qt.io/topic/67417/advanced-powerful-and-easy-to-use-orm-for-qt5

                            1 Reply Last reply Reply Quote 1
                            • First post
                              Last post