Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • CMake CMake
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,812
    • Issues 3,812
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 7
    • Merge requests 7
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CMake
  • CMakeCMake
  • Issues
  • #17471
Closed
Open
Created Nov 15, 2017 by Alexander Korsunsky@akors

CUDA: Incompatible System compiler is used for try_compile, even when compatible compiler was passed in CMAKE_CXX_COMPILER

Hello, I am using CMake 3.9.3 with Fedora 26.

The system compiler on Fedora 26 is GCC version 7.1, which is not compatible with any of the CUDA versions (latest: 9.0).

Luckily, I have prepared a compatible compiler in /opt/gcc/6.4.0/bin/g++. I have passed it to CMake with

set(CMAKE_CXX_COMPILER /opt/gcc/6.4.0/bin/g++)

This, however is ignored by the try_compile with CUDA. The CUDA try_compile just calls which is nvcc without any additional flags, which causes nvcc to use the compiler it happens to find on the path. However, this one is the incompatible GCC version 7 compiler, and this causes try_compile to fail and the configuration step to stop.

Workarounds are:

  • Modify PATH variable to put the custom g++ on the PATH, before the system compiler
  • Before calling cmake, set CUDAHOSTCXX environment variable
  • Turning a simple project(myproject VERSION 1.0.0 LANGUAGES C CXX CUDA) call into this:
project(myproject VERSION 1.0.0 LANGUAGES C CXX)

# When enabling the CUDA language, CMake uses the host compiler from PATH
# unless we specify the CUDAHOSTCXX environment variable
if ("$ENV{CUDAHOSTCXX}" STREQUAL "")
  set(ENV{CUDAHOSTCXX} ${CMAKE_CXX_COMPILER})
endif()
enable_language(CUDA)

These Workarounds "work", but I highly suggest to change the logic in CMake to use the value provided in CMAKE_CXX_COMPILER for the -ccbin option.

For that matter, I think it's not enough to allow -ccbin to be set only as an environment variable, I believe this should be settable by a distinct CMake variable.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking