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

building in debug mode, cmake and qmake link to debug and release build of Qt respectively

    XMLWordPrintable

    Details

    • Platform/s:
      macOS

      Description

      I noticed this inconsistency between qmake and CMake: qmake always links to release build of Qt, while CMake will link to debug build of Qt if build type is debug.

      Small project to demonstrate:

      *one.cpp*

      #include <QApplication>

      int main(int argc, char **argv)

      {

          QApplication app(argc, argv); return app.exec();

      }

      *one.pro*

      TEMPLATE += app
      CONFIG += debug
      QT += core gui widgets
      SOURCES += one.cpp
      TARGET = one

      *CMakeLists.txt*

      project(one)
      set(CMAKE_BUILD_TYPE DEBUG)
      set(CMAKE_MACOSX_RPATH 1)
      find_package(Qt5Core REQUIRED)
      find_package(Qt5Gui REQUIRED)
      find_package(Qt5Widgets REQUIRED)
      add_executable(one MACOSX_BUNDLE one.cpp)
      target_link_libraries(one Qt5::Core Qt5::Gui Qt5::Widgets)

      *Comparing the two builds:*

      Building with qmake:

      $ (mkdir build-qmake && cd build-qmake && ~/Qt/5.12.5/clang_64/bin/qmake .. && make)

      $ otool -L build-qmake/one.app/Contents/MacOS/one
      build-qmake/one.app/Contents/MacOS/one:
      @rpath/QtWidgets.framework/Versions/5/QtWidgets (compatibility version 5.12.0, current version 5.12.5)
      @rpath/QtGui.framework/Versions/5/QtGui (compatibility version 5.12.0, current version 5.12.5)
      @rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.12.0, current version 5.12.5)
      /System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
      /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility version 1.0.0, current version 1.0.0)
      /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.4)
      /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)

      Building with CMake:

      $ (mkdir build-cmake && cd build-cmake && cmake .. && cmake --build .)

      $ otool -L build-cmake/one.app/Contents/MacOS/one
      build-cmake/one.app/Contents/MacOS/one:
      @rpath/QtWidgets.framework/Versions/5/QtWidgets_debug (compatibility version 5.12.0, current version 5.12.5)
      @rpath/QtGui.framework/Versions/5/QtGui_debug (compatibility version 5.12.0, current version 5.12.5)
      @rpath/QtCore.framework/Versions/5/QtCore_debug (compatibility version 5.12.0, current version 5.12.5)
      /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.0)
      /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.50.4)

      Note: it links to the *_debug* builds.

      Also, do you know how to make CMake link against Qt release despite being in debug build? Can't find a simple answer to this.

      Anyway, one of the two (amongst qmake and CMake) has wrong defaults.

      This makes impossible to mix libraries built with the two build tools in the same deployed app, as you will get errors such as:

      objc[17828]: Class QMacAutoReleasePoolTracker is implemented in both [...]/some.app/Contents/Frameworks/QtCore.framework/Versions/5/QtCore (0x104748200) and [...]/some.app/Contents/Frameworks/QtCore.framework/Versions/5/QtCore_debug (0x11316ede8). One of the two will be used. Which one is undefined.

      which later lead to a crash.

        Attachments

          Issue Links

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

            Activity

              People

              Assignee:
              alexandru.croitor Alexandru Croitor
              Reporter:
              ff Federico Ferri
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes