1

I am working on a c++/cuda program using a Linux CentOS 7.9.2009 Server via VS Code SSH-Remote. The default compiler on the Linux machine is g++ (GCC) 4.8.5 but to use the cuda libraries I need a higher version (supporting std=c++14) which is provided on the machine by the devtoolset-8. To build my project I am using the Cmake extention of VS Code which works fine with the native compiler 4.8.5 but I can't find a way to integrate the devtoolset into Cmake or VS Code settings to work properly.

In the VS Code Cmake extention I already integrated a new Kit with the path to the devtoolset. Cmake finds the path to the new compiler version when creating the project but when I hit the build button of the Cmake extention in VS Code, it still uses the old version for the build (I get a build error that -std=c++14 is not supported by the compiler). My workaround is to compile the project manually in the console with scl enable devtoolset-8 'cmake3 ../src && make all' but then I dont't have Intellisense Code highlighting for errors and warnings in VS Code which I would like to have (I am a beginner by the way). Does anyone know if and how I can make VS Code with Cmake extention and the devtoolset work together to have Intellisense Code highlighting?

This is my cmake-tools-kits.json and the CMAKE Output:

  {
    "name": "GCC 4.8.5 x86_64-redhat-linux",
    "compilers": {
      "C": "/usr/bin/gcc",
      "CXX": "/usr/bin/g++"
    }
  },
  {
    "name": "GCC 8.3.1 x86_64-redhat-linux",
    "compilers": {
      "C": "/opt/rh/devtoolset-8/root/usr/bin/gcc",
      "CXX": "/opt/rh/devtoolset-8/root/usr/bin/g++"
    }
  }
]

 --------------------------------------------------------------

[cmake] -- The CXX compiler identification is GNU 8.3.1
[cmake] -- The CUDA compiler identification is NVIDIA 11.2.67
[cmake] -- Check for working CXX compiler: /opt/rh/devtoolset-8/root/usr/bin/g++
[cmake] -- Check for working CXX compiler: /opt/rh/devtoolset-8/root/usr/bin/g++ - works
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
rioV8
  • 24,506
  • 3
  • 32
  • 49
bonestorm
  • 11
  • 2
  • All kind of syntax errors should be highlighted, I am a beginner in c++ and cuda aswell, it would make my work way easier if they were higlighted. I think the problem is, that VS code or Cmake can't find the new compiler version. It still uses the old version dispite I gave both the path to the newer version – bonestorm Jul 07 '22 at 08:32
  • Can you confirm if you have enabled error highlighting? See [Enable error highlight in Visual Studio Code](https://stackoverflow.com/questions/61166385/enable-error-highlight-in-visual-studio-code). Or the problem is specific to using cmake, and devtoolset together? – Jason Jul 07 '22 at 08:44
  • Yes the highliting is enabled and works with the native compiler 4.8.5. It seems to be a problem with the devtoolset and cmake. When building the project VSCode/Cmake uses the old compiler version. How can I set the toolset to be the used compiler? – bonestorm Jul 07 '22 at 08:52
  • You should add the setting/json file in your question by clicking on the [edit](https://stackoverflow.com/posts/72894515/edit) button so that it is formatted nicely. – Jason Jul 07 '22 at 08:56

0 Answers0