14

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.

Sam G
  • 189
  • 1
  • 1
  • 10
  • Possible duplicate of [CMake: use a custom linker](https://stackoverflow.com/questions/1867745/cmake-use-a-custom-linker) – Tsyvarev Aug 01 '17 at 17:07
  • 4
    I specifid that setting the CMAKE_LINKER variable did not work, which is the solution to that quesiton. – Sam G Aug 01 '17 at 19:46
  • 1
    It is `CMAKE_{C,CXX}_LINK_EXECUTABLE`. – arrowd Aug 01 '17 at 20:15
  • Read [the answer](https://stackoverflow.com/a/25274328/3440745) carefully: aside from `CMAKE_LINKER` it specifies `CMAKE_CXX_LINK_EXECUTABLE` variable. – Tsyvarev Aug 01 '17 at 20:15
  • I specified that it did not help in the edit. – Sam G Aug 01 '17 at 21:25
  • 1
    So your linker doesn't support option `-Werror=date-time`. Because this is actually a **compiler** option, you may try to remove `` from `CMAKE_CXX_LINK_EXECUTABLE` definition. – Tsyvarev Aug 01 '17 at 22:20
  • Removing `` gives me the error `ld.gold: -Wl, -allow-shlib-undefined: unknown option`. I've tried almost every permutation of variables possible now, with no luck. – Sam G Aug 02 '17 at 17:51

1 Answers1

14

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

kirbyfan64sos
  • 10,377
  • 6
  • 54
  • 75