question

MedovyVladimirCanonPP avatar image
1 Vote"
MedovyVladimirCanonPP asked MedovyVladimirCanonPP commented

Why does IntelliSense not find system headers (e.g. `string`) of custom cross toolchains when using CMake?

I would like to use Visual Studio 2019 (Version 16.9.4) to develop Linux applications for a custom embedded board with a custom toolchain and CMake. To achieve this, I created a CMake toolchain file and passed it via the cmakeToolchain option in CMakeSettings.json. CMake chooses the correct toolchain during build system generation (generator is Ninja) and can build the project succesfully.

However, IntelliSense does not work as expected. If I set inheritEnvironments to something like linux_arm, then IntelliSense uses the system headers (e.g. string) associated to this environment (e.g. C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\VC\Linux\include\usr\include\c++\5\string). This are not the headers from the configured toolchain.

If I do not set inheritEnvironments to anything (i.e. pass an empty array), then the system header are not found at all and IntelliSense basically stops working.

I followed the recommendations from https://devblogs.microsoft.com/cppblog/configure-intellisense-with-cmake-toolchain-files-in-visual-studio-2019-16-9-preview-2/ and set intelliSenseMode to linux-gcc-arm, but that did not change anything (meaning that the system headers are still not found at all). The toolchain file configures CMAKE_C_COMPILER and CMAKE_CXX_COMPILER, so it should have worked. Just to make sure, I set useCompilerDefaults to true under intellisenseOptions. Still, no change.

Here is the content of the toolchain file:
```
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)

set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
```
The compiler is available on PATH and Visual Studio correctly expands the path to its absolute path in CMakeCache.txt.

The content of CMakeSettings.json is
```
{
"configurations": [
{
"name": "aarch64-linux-gnu_Debug",
"generator": "Ninja",
"configurationType": "Debug",
"buildRoot": "${projectDir}\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"cmakeToolchain": ".cmake_toolchain_definitions/aarch64-linux-gnu.cmake",
"inheritEnvironments": [],
"intelliSenseMode": "linux-gcc-arm",
"intellisenseOptions": {"useCompilerDefaults": true}
}
]
}
```

What can I do to make IntelliSense work and find the correct system headers of the custom toolchain?




c++vs-general
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Dear customer, according to your description, it seems your issue more relates to the CMake and that out of our support scope, please redirect to this appropriate forum: https://discourse.cmake.org/ to seek for a better support, thanks for your understanding.

0 Votes 0 ·

Hey @SaraLiu-MSFT,

thanks you for your reply.

However, I fail to see how IntelliSense not working is a CMake issue. Here is a quote from my question:

CMake chooses the correct toolchain during build system generation (generator is Ninja) and can build the project succesfully.

Due to this, I am quite sure that this is not a CMake issue. JetBrains CLion finds the headers in the same environment. The contents of CMakeCache.txt between Visual Studio and CLion do not differ significantly.

It probably has something to do with inheritEnvironments. It might be that I need to define a custom environment. The ability to define such an environment is mentioned in some posts about the Visual Studio CMake support. However, I could not find any specific documentation on how to do so, what variables such a custom environment consists of and which of them are relevant to get IntelliSense to work. Any information about that would be highly appreciated. :)

Thank you very much!

0 Votes 0 ·

Also, if some crucial information is missing from my description and some additional information is required to analyze the issue at hand, then I will gladly provide it. :)

0 Votes 0 ·

0 Answers