Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to Change Default Linker in CMake

I am trying to change my linker to ld.gold so that I can build LLVM and CLANG faster. I have changed my environment variable with:

export LD=ld.gold

and I have changed CMAKE_LINKER in ccmake to /usr/bin/ld.gold. However, when I generate the files, my linker is detected as GNU ld. Running top during compilation confirms that ld is running rather than gold.

When editing the CMake Link Executable variable to:

cmake -DCMAKE_LINKER=/usr/bin/ld.gold -DCMAKE_CXX_LINK_EXECUTABLE="<CMAKE_LINKER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" -G "Unix Makefiles" ../llvm

I receive the following error:

/usr/bin/ld.gold: -Werror=date-time: unknown option
/usr/bin/ld.gold: use the --help option for usage information
utils/PerfectShuffle/CMakeFiles/llvm-PerfectShuffle.dir/build.make:94: recipe for target 'bin/llvm-PerfectShuffle' failed
make[2]: *** [bin/llvm-PerfectShuffle] Error 1
CMakeFiles/Makefile2:13983: recipe for target 'utils/PerfectShuffle/CMakeFiles/llvm-PerfectShuffle.dir/all' failed

I'm on Ubuntu 16.04, but I have had the same problem on Arch Linux.

Thank You.

like image 869
Sam G Avatar asked Aug 01 '17 16:08

Sam G


1 Answers

CMAKE_EXE_LINKER_FLAGS=-fuse-ld=gold will pass -fuse-ld=gold to the compiler, which will properly use the gold linker.

like image 127
kirbyfan64sos Avatar answered Oct 12 '22 16:10

kirbyfan64sos