Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-24662

qmake do not properly handle -arch arg linker flag

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • 4.7.4, 4.8.x
    • Build tools: qmake
    • None
    • mac

    Description

      qmake handling of LIBS is broken when used on a mac should the -arch flag be used.

      -arch determine what architecture the compiler/linker should use: like so:
      calling the linker with -arch x86_64 -arch i386 will tell the linker to link against both 64 bits and 32 bits intel libs.

      When adding to LIBS however, qmake optimises what is added and can drop the -arch argument.

      Example

      LIBS = -arch i386 -arch x86_64
      FOO = -arch i386 -arch x86_64 -lmysqlclient
      LIBS += FOO
      

      the resulting LIBS generated in the Makefile will be:
      LIBS = -arch i386 -arch x86_64 -arch -arch

      Notice that the second i386 and x86_64 arguments have been dropped.
      This will result in a broken compilation with the linker complaining about "invalid architecture -arch"

      A side effect of this problem is that it breaks Qt compilation itself should you try to compile the QtSql's plugin mysql.

      The configure script calls mysql_config --libs to identify what flags to use when linking mysql.
      mysql_config --libs returns:

      -Wl,-syslibroot,/Applications/Custom/Development/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -L/Users/jyavenard/Work/mythtv/.osx-packager/build/lib -F/Users/jyavenard/Work/mythtv/.osx-packager/build/lib -arch x86_64  -L/Users/jyavenard/Work/mythtv/.osx-packager/build/lib/mysql -lmysqlclient -lz -lm
      

      should mysql be compiled for x86_64 target and:

      -Wl,-syslibroot,/Applications/Custom/Development/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -L/Users/jyavenard/Work/mythtv/.osx-packager/build/lib -F/Users/jyavenard/Work/mythtv/.osx-packager/build/lib -arch i386 -arch x86_64  -L/Users/jyavenard/Work/mythtv/.osx-packager/build/lib/mysql -lmysqlclient -lz -lm
      

      configure then add it to LIBS.

      If Qt is compiled with -arch i386 or -arch x86_64, the current LIBS already contains the -arch argument, so when the LIBS is generated, the argument to -arg is dropped and you end with a Makefile like so:

      -Wl,-syslibroot,/Applications/Custom/Development/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -L/Users/jyavenard/Work/mythtv/.osx-packager/build/lib -F/Users/jyavenard/Work/mythtv/.osx-packager/build/lib -arch -arch -L/Users/jyavenard/Work/mythtv/.osx-packager/build/lib/mysql -lmysqlclient -lz -lm
      

      which will crash.

      qmake shouldn't try to simplify -arch arg, and should it drop the argument, to also drop the -arch preceding.

      One work around would be to add quotes, however then qmake escape the space between -arch and i386 and it becomes:
      -arch\ i386
      which is also invalid

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            buddenha Oswald Buddenhagen
            jyavenard Jean-Yves Avenard
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes