Skip to content

Intellisense of CMake-Tools is not working with MSYS2. #2086

@hwhsu1231

Description

@hwhsu1231

Problem Description

Recently, I've done the research on how to build the environment of MSYS in VSCode. First to say, it actually worked. I wrote a simple program with fork(), and it could run successfully. However, the intellisence of CMake-Tools shows that it could not locate the headers with the squiggles underneath.

#include errors detected based on information provided by the configurationProvider setting. Squiggles are disabled for this translation unit

Usually, I don't use c_cpp_properties.json because CMake-Tools will help me to to intellisense whether I work in Windows or Linux, thanks to the ms-vscode.cmake-tools. That is awesome, by the way, because I don't have to worry about intellisense of C/C++. But it looks like it cannot work well on MSYS environment.

Steps of Building Environment for MSYS

  • Download the MSYS2 installer from its website, and follow the instructions listed on the home page to synchronize databases.

  • Use pacman to install the toolchain of MSYS, msys2-devel.

    pacman -S msys2-devel
  • After installing msys2-devel, I add the directory of compiler, C:\msys64\usr\bin, to the environment variable, PATH, so that CMake-Tools can scan for this kit.

  • Open VSCode and input CMake: Scan for Kits in Command Palette, and then choose the GCC 10.2.0 x86_64-pc-msys.

  • Input CMake: Edit User-Local CMake Kits in Command Palette to open cmake-tools-kits.json. Then, add MSYS Makefiles as the preferredGenerator for the kit GCC 10.2.0 x86_64-pc-msys, like this:

    "name": "GCC 10.2.0 x86_64-pc-msys",
    "compilers": {
        "C": "C:\\msys64\\usr\\bin\\x86_64-pc-msys-gcc.exe",
        "CXX": "C:\\msys64\\usr\\bin\\x86_64-pc-msys-g++.exe"
    },
    "preferredGenerator": {
        "name": "MSYS Makefiles"
    }
    
  • In order to simulate the POSIX shell, I copy the msys-2.0.dll to the output bin directory. But first, I need to locate where msys-2.0.dll is, so I use the following code to do it:

    if(MSYS)
        get_filename_component(msys_bindir "${CMAKE_C_COMPILER}" PATH)
        set(msys_dll_file "${msys_bindir}/msys-2.0.dll")
        file(COPY "${msys_dll_file}" DESTINATION "${output_bindir}")
    endif(MSYS)

Here is my code

vscode-cmake-tools-msys.zip

Screenshots of Result

pic_02
pic_03
pic_04

Platform and Versions

  • Operating System: Windows 11
  • CMake Version: 3.21.1
  • VSCode Version: 1.59.1
  • CMake Tools Extension Version: 1.8.0
  • MSYS Toolchain: 10.2.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions