Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-17288

cmake projects using clang cross compilation cannot find stdlib include directories

    XMLWordPrintable

Details

    Description

      If I use gcc, my toolchain file has those lines amongst others:

      arm_gcc.cmake
      set(CMAKE_SYSROOT "<sysroot_path>")
      set(CMAKE_CXX_COMPILER ${CMAKE_SYSROOT}/usr/bin/arm-poky-linux-gnueabi-g++)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=cortex-a15 -mfloat-abi=hard -mthumb -m32" CACHE STRING "")
      

      When I want to use clang, those lines change to:

      arm_clang.cmake
      set(CMAKE_SYSROOT "<sysroot_path>")
      set(CMAKE_CXX_COMPILER /opt/clang/3.9.0/bin/clang++)
      set(CMAKE_CXX_COMPILER_TARGET "arm-poky-linux-gnueabi")
      set(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN ${CMAKE_SYSROOT}/usr) 
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=cortex-a15 -mfloat-abi=hard -mthumb -m32" CACHE STRING "")
      

      Building process works in both cases without any visible issues in both QtCreator and by manually launching cmake with proper arguments (cmake -H. -Bbuild -DCMAKE_TOOLCHAIN_FILE=arm_(gcc|clang).cmake). However, if I inspect code model in QtCreator, the version with clang doesn't add the following include directories:

      CMAKE_SYSROOT/usr/include/c++/5.4.0
      CMAKE_SYSROOT/usr/include/c++/5.4.0/arm-poky-linux-gnueabi
      CMAKE_SYSROOT/usr/include/c++/5.4.0/backward
      CMAKE_SYSROOT/usr/lib/gcc/arm-poky-linux-gnueabi/5.4.0/include
      CMAKE_SYSROOT/usr/include

      Manually adding the mentioned directories is possible only for the first four as adding the last one has no effect on code model.

      The effect is that clang code model cannot find stdlib headers and, for instance, finds incorrect boost headers (from /usr/include/boost instead of CMAKE_SYSROOT/usr/include/boost)

      Kits have rather standard options with only one cmake variable CMAKE_TOOLCHAIN_FILE (as CMAKE_<LANG>_COMPILER are defined inside CMAKE_TOOLCHAIN_FILE) pointing to various toolchain files (either gcc which works find or clang which doesn't).

      So basically, cross compiling with clang that uses non standard gcc location (so --gcc-toolchain parameter must be set) works but clang code model doesn't cope with it.

      Is there any workaround for this problem?

      Attachments

        1. clang.cmake
          0.3 kB
        2. gcc.cmake
          0.1 kB

        Issue Links

          Activity

            People

              hunger Tobias Hunger
              jackspruce Anonymous (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: