Skip to content

CUDA: Pass host compiler to nvcc while device linking

MvdHurk requested to merge vanderhu/cmake:bugfix/CUDACrosscompile into master

Without using this flags you will notice when cross-compiling for example for aarch64 problems with cmake_device_link.o. See:

/usr/local/cuda/bin/nvcc -Xcompiler=-fPIC -Wno-deprecated-gpu-targets
  -shared -dlink CMakeFiles/cmTC_64cf1.dir/main.cu.o -o
  CMakeFiles/cmTC_64cf1.dir/cmake_device_link.o
  Linking CUDA executable cmTC_64cf1

  /opt/apps/cmake-3.9.0-Linux-x86_64/bin/cmake -E cmake_link_script
  CMakeFiles/cmTC_64cf1.dir/link.txt --verbose=1

  /usr/bin/aarch64-linux-gnu-g++
  CMakeFiles/cmTC_64cf1.dir/main.cu.o
  CMakeFiles/cmTC_64cf1.dir/cmake_device_link.o -o cmTC_64cf1
  -L"/usr/local/cuda/targets/aarch64-linux/lib/stubs"
  -L"/usr/local/cuda/targets/aarch64-linux/lib" -lcudadevrt -lcudart_static
  -lrt -lpthread -ldl

  /usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld:
  CMakeFiles/cmTC_64cf1.dir/cmake_device_link.o: Relocations in generic ELF
  (EM: 62)
  /usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld:
  CMakeFiles/cmTC_64cf1.dir/cmake_device_link.o: Relocations in generic ELF
  (EM: 62)
  /usr/lib/gcc-cross/aarch64-linux-gnu/5/../../../../aarch64-linux-gnu/bin/ld:
  CMakeFiles/cmTC_64cf1.dir/cmake_device_link.o: Relocations in generic ELF
  (EM: 62)
  CMakeFiles/cmTC_64cf1.dir/cmake_device_link.o: error adding symbols: File
  in wrong format

Topic-rename: cuda-device-link-ccbin

Edited by Brad King

Merge request reports