Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    qmake LIBS variable: is it necessary to have separate win32 and unix scopes?

    General and Desktop
    qmake libs win32 unix
    4
    4
    1349
    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.
    • B
      Bart_Vandewoestyne last edited by

      I am working on legacy code that has a lot of the following in its qmake .pro files:

      win32 {
          LIBS += SomeCoolLib.lib \
                  SomeOtherLib.lib
      }
      
      unix {
          LIBS += -lSomeCoolLib \
                  -lSomeOtherLib
      }
      

      Adding or removing libraries to LIBS means that I have to add or remove things at two places in this .pro file. Since the libraries are the same for both windows and unix, i was wondering if I can write this shorter. I am using Qt 4.8, so reading the docs at http://doc.qt.io/qt-4.8/qmake-variable-reference.html#libs I found that I can probably replace the windows and unix scope by this one scope if I use the -l option:

      LIBS += -lSomeCoolLib \
              -lSomeOtherLib
      

      However, on the same documentation page, the Note recommends against this and advises to explicitly specify the library to be used by including the .lib file name suffix, which would again mean having two scopes.

      If the libraries on windows and unix are the same, then is there a way to specify them only once? Or should I stick with the two scopes and use .lib for windows and -l for unix?

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

        Hi,

        It depends on the situation you have at hand. If you need to link to a specific version of a library then go with the scopes otherwise you don't need to.

        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
        • A
          alearner @Bart_Vandewoestyne last edited by

          @Bart_Vandewoestyne
          i think what you want is

          win32 {
              somecool  = SomeCoolLib.lib 
                      someother = SomeOtherLib.lib
          }
          unix {
              somecool = -lSomeCoolLib 
                     someother =  -lSomeOtherLib
          }
          
          LIBS += somecool \
                  someother 
          
          1 Reply Last reply Reply Quote 0
          • N
            NetZwerg last edited by

            As soon as paths or library names differ, you will have to use scoped declarations. Otherwise it really does not matter. Win32 also links correctly using -lSomeCoolLib, therefor you could just use one LIBS directive.

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