How to use LLVM linker (ld.lld) instead of GNU linker (ld)
-
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:
space
I see no option to configure the linker ?!
-
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
forCMAKE_EXE_LINKER_FLAGS
. -
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 ?
-
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" afterlld
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.
-
@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)
-
For CMake you can pass
--verbose
for the build line, with QMake andmake
you can passVERBOSE=1
to the make line in project settings. -
@cristian-adam I remember that there was a command used to check the executable and with what it was linked!