Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. How to use LLVM linker (ld.lld) instead of GNU linker (ld)

How to use LLVM linker (ld.lld) instead of GNU linker (ld)

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
8 Posts 4 Posters 4.6k 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.
  • P Offline
    P Offline
    Pete Carter
    wrote on 5 Sept 2023, 11:23 last edited by Pete Carter 9 May 2023, 12:37
    #1

    My sys info:

    Operating System: Fedora Linux 38
    KDE Plasma Version: 5.27.7
    KDE Frameworks Version: 5.109.0
    Qt Version: 5.15.10
    Kernel Version: 6.4.13-200.fc38.x86_64 (64-bit)
    Graphics Platform: Wayland
    

    GCC and ld are the default settings for building a C++ project. I managed to use clang and configure it alongside GCC, How can i add the LLVM linker (ld.lld) instead of GCC linker (ld) to be used by my project ?


    This is the commands being run in the compile output:

    clang++ -c -pipe -g -std=gnu++2a -Wall -Wextra -DQT_QML_DEBUG -I../../cpp_for_dummies -I. -I../../../../Qt/6.5.2/gcc_64/mkspecs/linux-clang -o main.o ../main.cpp

    clang++ -ccc-gcc-name g++ -o cpp_for_dummies add.o main.o

    In the second command -ccc-gcc-name g++ is being used, which probably means to use the GNU linker ld. How can i change that to LLVM linker ld.lld ?


    These are my GCC and Clang kits configs:

    Screenshot_20230905_142516.png
    space
    Screenshot_20230905_142548.png

    I see no option to configure the linker ?!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SimonSchroeder
      wrote on 6 Sept 2023, 07:58 last edited by
      #2

      Similar to your use case I have the following line in my qmake project file:

      QMAKE_LFLAGS += -fuse-ld=gold
      

      This seems to translate to -fuse-ld=lld for CMAKE_EXE_LINKER_FLAGS.

      P 1 Reply Last reply 6 Sept 2023, 08:23
      0
      • S SimonSchroeder
        6 Sept 2023, 07:58

        Similar to your use case I have the following line in my qmake project file:

        QMAKE_LFLAGS += -fuse-ld=gold
        

        This seems to translate to -fuse-ld=lld for CMAKE_EXE_LINKER_FLAGS.

        P Offline
        P Offline
        Pete Carter
        wrote on 6 Sept 2023, 08:23 last edited by Pete Carter 9 Jun 2023, 08:23
        #3

        @SimonSchroeder

        So in my case it should be QMAKE_LFLAGS += -fuse-ld=lld ?

        Isn't there an option to specify this in the settings so it's used in all the projects, like hardcode it in the kit settings ?

        C 1 Reply Last reply 7 Sept 2023, 14:52
        0
        • P Pete Carter
          6 Sept 2023, 08:23

          @SimonSchroeder

          So in my case it should be QMAKE_LFLAGS += -fuse-ld=lld ?

          Isn't there an option to specify this in the settings so it's used in all the projects, like hardcode it in the kit settings ?

          C Online
          C Online
          cristian-adam
          wrote on 7 Sept 2023, 14:52 last edited by
          #4

          In the kit you have the Qt mkspec: field which could point to a mkspec that includes this feature.

          I have the mkspecs here: c:\Qt\6.4.3\mingw_64\mkspecs, and a "grep" after lld pointed to:

          C:\Qt\6.4.3\mingw_64\mkspecs
          $ findstr /spin /c:"lld" /l *
          common\gcc-base-unix.conf:25:QMAKE_LFLAGS_USE_LLD    = -fuse-ld=lld
          features\default_post.prf:85:    use_lld_linker: QMAKE_LFLAGS += $$QMAKE_LFLAGS_USE_LLD
          features\qt_configure.prf:399:    use_lld_linker: \
          features\qt_configure.prf:400:        LFLAGS = -fuse-ld=lld
          features\qt_configure.prf:1216:    use_lld_linker: \
          features\qt_configure.prf:1217:        qmake_configs += "use_lld_linker"
          features\qt_docs.prf:68:    QDOC += -installdir $$shell_quote($$[QT_INSTALL_DOCS])
          features\qt_helper_lib.prf:28:DLLDESTDIR = $$MODULE_BASE_OUTDIR/bin
          features\qt_module.prf:94:DLLDESTDIR       = $$MODULE_BASE_OUTDIR/bin
          features\toolchain.prf:333:            dir = $$(VSINSTALLDIR)
          features\toolchain.prf:349:            dir = $$(VCINSTALLDIR)
          macx-xcode\default.xcscheme:26:      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
          macx-xcode\default.xcscheme:27:      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
          macx-xcode\default.xcscheme:60:      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
          macx-xcode\default.xcscheme:61:      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
          modules\qt_lib_core_private.pri:11:QT.core_private.disabled_features = clock-gettime system-doubleconversion dladdr futimens futimes getauxval getentropy glib glibc icu inotify journald system-libb2 linkat system-pcre2 poll_ppoll poll_pollts poll_poll poll_select qqnx_pps renameat2 slog2 statx syslog backtrace cpp-winrt lttng etw forkfd_pidfd use_bfd_linker use_gold_linker use_lld_linker use_mold_linker android-style-assets gc_binaries developer-build no-prefix private_tests debug no_direct_extern_access mips_dsp mips_dspr2 neon arm_crc32 arm_crypto posix_fallocate alloca_h stack-protector-strong system-zlib stdlib-libcpp dbus-linked libudev dlopen intelcet
          qmodule.pri:3:QT.global_private.disabled_features = use_bfd_linker use_gold_linker use_lld_linker use_mold_linker android-style-assets gc_binaries developer-build no-prefix private_tests debug no_direct_extern_access mips_dsp mips_dspr2 neon arm_crc32 arm_crypto posix_fallocate alloca_h stack-protector-strong system-zlib stdlib-libcpp dbus-linked libudev dlopen intelcet
          win32-clang-msvc\qmake.conf:40:QMAKE_LINK              = lld-link
          win32-clang-msvc\qmake.conf:52:# Leave QMAKE_LFLAGS_LTCG empty because lld-link doesn't need any additional parameters
          

          Maybe it works pointing to a custom mkspec not being part of the system ones.

          C 1 Reply Last reply 9 Sept 2023, 04:54
          1
          • C cristian-adam
            7 Sept 2023, 14:52

            In the kit you have the Qt mkspec: field which could point to a mkspec that includes this feature.

            I have the mkspecs here: c:\Qt\6.4.3\mingw_64\mkspecs, and a "grep" after lld pointed to:

            C:\Qt\6.4.3\mingw_64\mkspecs
            $ findstr /spin /c:"lld" /l *
            common\gcc-base-unix.conf:25:QMAKE_LFLAGS_USE_LLD    = -fuse-ld=lld
            features\default_post.prf:85:    use_lld_linker: QMAKE_LFLAGS += $$QMAKE_LFLAGS_USE_LLD
            features\qt_configure.prf:399:    use_lld_linker: \
            features\qt_configure.prf:400:        LFLAGS = -fuse-ld=lld
            features\qt_configure.prf:1216:    use_lld_linker: \
            features\qt_configure.prf:1217:        qmake_configs += "use_lld_linker"
            features\qt_docs.prf:68:    QDOC += -installdir $$shell_quote($$[QT_INSTALL_DOCS])
            features\qt_helper_lib.prf:28:DLLDESTDIR = $$MODULE_BASE_OUTDIR/bin
            features\qt_module.prf:94:DLLDESTDIR       = $$MODULE_BASE_OUTDIR/bin
            features\toolchain.prf:333:            dir = $$(VSINSTALLDIR)
            features\toolchain.prf:349:            dir = $$(VCINSTALLDIR)
            macx-xcode\default.xcscheme:26:      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
            macx-xcode\default.xcscheme:27:      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
            macx-xcode\default.xcscheme:60:      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
            macx-xcode\default.xcscheme:61:      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
            modules\qt_lib_core_private.pri:11:QT.core_private.disabled_features = clock-gettime system-doubleconversion dladdr futimens futimes getauxval getentropy glib glibc icu inotify journald system-libb2 linkat system-pcre2 poll_ppoll poll_pollts poll_poll poll_select qqnx_pps renameat2 slog2 statx syslog backtrace cpp-winrt lttng etw forkfd_pidfd use_bfd_linker use_gold_linker use_lld_linker use_mold_linker android-style-assets gc_binaries developer-build no-prefix private_tests debug no_direct_extern_access mips_dsp mips_dspr2 neon arm_crc32 arm_crypto posix_fallocate alloca_h stack-protector-strong system-zlib stdlib-libcpp dbus-linked libudev dlopen intelcet
            qmodule.pri:3:QT.global_private.disabled_features = use_bfd_linker use_gold_linker use_lld_linker use_mold_linker android-style-assets gc_binaries developer-build no-prefix private_tests debug no_direct_extern_access mips_dsp mips_dspr2 neon arm_crc32 arm_crypto posix_fallocate alloca_h stack-protector-strong system-zlib stdlib-libcpp dbus-linked libudev dlopen intelcet
            win32-clang-msvc\qmake.conf:40:QMAKE_LINK              = lld-link
            win32-clang-msvc\qmake.conf:52:# Leave QMAKE_LFLAGS_LTCG empty because lld-link doesn't need any additional parameters
            

            Maybe it works pointing to a custom mkspec not being part of the system ones.

            C Offline
            C Offline
            ChrisW67
            wrote on 9 Sept 2023, 04:54 last edited by
            #5

            @Pete-Carter Looks to me like:

            CONFIG += use_lld_linker
            

            in your PRO file would switch linker without affecting the GCC compiler..

            I am not certain of the CMakeLists.txt equivalent, perhaps:

            set(QT_FEATURE_use_lld_linker ON)
            
            P 1 Reply Last reply 9 Sept 2023, 07:20
            0
            • C ChrisW67
              9 Sept 2023, 04:54

              @Pete-Carter Looks to me like:

              CONFIG += use_lld_linker
              

              in your PRO file would switch linker without affecting the GCC compiler..

              I am not certain of the CMakeLists.txt equivalent, perhaps:

              set(QT_FEATURE_use_lld_linker ON)
              
              P Offline
              P Offline
              Pete Carter
              wrote on 9 Sept 2023, 07:20 last edited by
              #6

              @ChrisW67

              Is there a way to check that it worked, to check if the executable was linked with ld or lld ?

              C 1 Reply Last reply 9 Sept 2023, 07:44
              0
              • P Pete Carter
                9 Sept 2023, 07:20

                @ChrisW67

                Is there a way to check that it worked, to check if the executable was linked with ld or lld ?

                C Online
                C Online
                cristian-adam
                wrote on 9 Sept 2023, 07:44 last edited by
                #7

                For CMake you can pass --verbose for the build line, with QMake and make you can pass VERBOSE=1 to the make line in project settings.

                P 1 Reply Last reply 9 Sept 2023, 08:42
                0
                • C cristian-adam
                  9 Sept 2023, 07:44

                  For CMake you can pass --verbose for the build line, with QMake and make you can pass VERBOSE=1 to the make line in project settings.

                  P Offline
                  P Offline
                  Pete Carter
                  wrote on 9 Sept 2023, 08:42 last edited by
                  #8

                  @cristian-adam I remember that there was a command used to check the executable and with what it was linked!

                  1 Reply Last reply
                  0

                  3/8

                  6 Sept 2023, 08:23

                  topic:navigator.unread, 5
                  • Login

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