Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In the case of compilation, intellisense always indicates that the header file cannot be found #3824

Closed
shawn1j opened this issue Jun 7, 2024 · 12 comments
Assignees
Labels
more info needed More info is needed from the community for us to properly triage and investigate.
Milestone

Comments

@shawn1j
Copy link

shawn1j commented Jun 7, 2024

Environment

  • OS and Version: windows 10 x64
  • VS Code Version: 1.90
  • C/C++ Extension Version: 1.20.5
  • If using SSH remote, specify OS of remote machine:

Bug Summary and Steps to Reproduce

Bug Summary:
I am using vscode to build my project, I use cmake to build my project, which uses qt library and some other third party libraries, my project can compile normally and run successfully. But in my code file, there is always an error ripple on this side of the #include header. This is a problem even with iostream headers. I tried to add a header search path for qt and other third-party libraries to the includePath field in the c_cpp_properties.json file, or "configurationProvider": "ms-vscode.cmake-tools", adds a path to the C_Cpp.default.includePath field in the settings.json file, but these attempts do not work, and the problem persists.

image

Below is the directory structure of my project:
C:\USERS\SJ2003\DESKTOP\VIDEOCALL
│ CMakeLists.txt
│ dialog.cpp
│ dialog.h
│ Dialog.ui

├─.vscode
│ c_cpp_properties.json

└─build
│ ALL_BUILD.vcxproj
│ ALL_BUILD.vcxproj.filters
│ CMakeCache.txt
│ cmake_install.cmake
│ VideoCall.sln
│ VideoCall.vcxproj
│ VideoCall.vcxproj.filters
│ ZERO_CHECK.vcxproj
│ ZERO_CHECK.vcxproj.filters

├─.cmake
│ └─api
│ └─v1
| .......

Configuration and Logs

my c_cpp_properties.json
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "D:/Edge/Agora_Native_SDK_for_Windows_v4.3.1_FULL/Agora_Native_SDK_for_Windows_FULL/sdk/high_level_api/include/**",
                "D:/QT6/6.4.3/msvc2019_64/include/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "configurationProvider": "ms-vscode.cmake-tools"
        }
    ],
    "version": 4
}

my settings.json
{
    "C_Cpp.errorSquiggles": "enabled",
    "C_Cpp.default.includePath": [
        "D:/Edge/Agora_Native_SDK_for_Windows_v4.3.1_FULL/Agora_Native_SDK_for_Windows_FULL/sdk/high_level_api/include/**",
        "D:/QT6/6.4.3/msvc2019_64/include/**"
    ]
}

my logs
[main] Creating a folder: videoCall
[build] is starting the build
[proc] Run the following command: D:\QT6\Tools\CMake_64\bin\cmake.exe --build c:/Users/sj2003/Desktop/videoCall/build --config Debug --target ALL_BUILD -j 14 --
[build] applies to.NET Framework MSBuild version 17.10.4+10fbfbf2e
[build] 
[build]   Automatic MOC and UIC for target VideoCall
[build]   mocs_compilation_Debug.cpp
[build] D: \ Edge \ Agora_Native_SDK_for_Windows_v4 3.1 _FULL \ Agora_Native_SDK_for_Windows_FULL \ SDK \ high_level_api \ include \ AgoraBase. h(5484,36): warning C4267: "initialization" : convert from "size_t" to "int", data may be lost [C:\Users\sj2003\Desktop\ VideoCall \build\ videocall.vcxproj]
[build] D: \ Edge \ Agora_Native_SDK_for_Windows_v4 3.1 _FULL \ Agora_Native_SDK_for_Windows_FULL \ SDK \ high_level_api \ include \ AgoraBase. h(5484,23): warning C4267: Initialization: When converting from "size_t" to "const int", data may be lost [C:\Users\sj2003\Desktop\ VideoCall \build\ videocall.vcxproj]
[build] D: \ Edge \ Agora_Native_SDK_for_Windows_v4 3.1 _FULL \ Agora_Native_SDK_for_Windows_FULL \ SDK \ high_level_api \ include \ AgoraBase. h(5499,36): warning C4267: "initialization" : convert from "size_t" to "int", data may be lost [C:\Users\sj2003\Desktop\ VideoCall \build\ videocall.vcxproj]
[build] D: \ Edge \ Agora_Native_SDK_for_Windows_v4 3.1 _FULL \ Agora_Native_SDK_for_Windows_FULL \ SDK \ high_level_api \ include \ AgoraBase. h(5499,23): warning C4267: Initialize: When converting from "size_t" to "const int", data may be lost [C:\Users\sj2003\Desktop\ VideoCall \build\ videocall.vcxproj]
[build]   dialog.cpp
[build] D: \ Edge \ Agora_Native_SDK_for_Windows_v4 3.1 _FULL \ Agora_Native_SDK_for_Windows_FULL \ SDK \ high_level_api \ include \ AgoraBase. h(5484,36): warning C4267: "initialization" : convert from "size_t" to "int", data may be lost [C:\Users\sj2003\Desktop\ VideoCall \build\ videocall.vcxproj]
[build] D: \ Edge \ Agora_Native_SDK_for_Windows_v4 3.1 _FULL \ Agora_Native_SDK_for_Windows_FULL \ SDK \ high_level_api \ include \ AgoraBase. h(5484,23): warning C4267: Initialization: When converting from "size_t" to "const int", data may be lost [C:\Users\sj2003\Desktop\ VideoCall \build\ videocall.vcxproj]
[build] D: \ Edge \ Agora_Native_SDK_for_Windows_v4 3.1 _FULL \ Agora_Native_SDK_for_Windows_FULL \ SDK \ high_level_api \ include \ AgoraBase. h(5499,36): warning C4267: "initialization" : convert from "size_t" to "int", data may be lost [C:\Users\sj2003\Desktop\ VideoCall \build\ videocall.vcxproj]
[build] D: \ Edge \ Agora_Native_SDK_for_Windows_v4 3.1 _FULL \ Agora_Native_SDK_for_Windows_FULL \ SDK \ high_level_api \ include \ AgoraBase. h(5499,23): warning C4267: Initialize: When converting from "size_t" to "const int", data may be lost [C:\Users\sj2003\Desktop\ VideoCall \build\ videocall.vcxproj]
[build] is generating code...
[build]   VideoCall.vcxproj -> C:\Users\sj2003\Desktop\videoCall\build\Debug\VideoCall.exe
[build]   Building Custom Rule C:/Users/sj2003/Desktop/videoCall/CMakeLists.txt
[driver] Generated: 00:00:09.403
[build] The build is complete and the exit code is 0

Other Extensions

cmake v0.0.17
cmake-tools v1.18.41
cmake language support v0.0.9

Additional context

CMakeLists.txt

@sean-mcmanus sean-mcmanus self-assigned this Jun 7, 2024
@sean-mcmanus
Copy link
Contributor

Are you trying to compile with cl.exe? Did you run CMake: Configure? When you run C/C++: Log Diagnostics with a C++ file active what is the output in regards to system includes?

@sean-mcmanus sean-mcmanus added the more info needed More info is needed from the community for us to properly triage and investigate. label Jun 7, 2024
@shawn1j
Copy link
Author

shawn1j commented Jun 8, 2024

Here is my configuration result, but it didn't work

[proc] Run the command D:\QT6\Tools\CMake_64\bin\cmake.exe --version
[proc] Run D:\QT6\Tools\CMake_64\bin\cmake.exe -E capabilities
[variant] A new set of variables is loaded
[kit] successfully loaded 15 toolkits from C:\Users\sj2003\AppData\Local\CMakeTools\cmake-tools-kits.json
[proc] Run the chcp command
[visual-studio] is patched from D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat C:\Program Files (x86)\Windows Kits\10\bin\x64 to C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64 Windows SDK path
[main] Configuring the project: videoCall
[proc] Run the following command: D:\QT6\Tools\CMake_64\bin\cmake.exe --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -SC:/Users/sj2003/Desktop/videoCall -Bc:/Users/sj2003/Desktop/videoCall/build -G "Visual Studio 17 2022" -T host=x64 -A x64
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
[cmake] -- The CXX compiler identification is MSVC 19.40.33811.0
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: D: / Program Files/Microsoft Visual Studio / 2022 / Community/VC/Tools/MSVC / 14.40.33807 / bin/Hostx64 / x64 / cl. Exe - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
[cmake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
[cmake] -- Looking for pthread_create in pthreads
[cmake] -- Looking for pthread_create in pthreads - not found
[cmake] -- Looking for pthread_create in pthread
[cmake] -- Looking for pthread_create in pthread - not found
[cmake] -- Found Threads: TRUE
[cmake] -- Performing Test HAVE_STDATOMIC
[cmake] -- Performing Test HAVE_STDATOMIC - Success
[cmake] -- Found WrapAtomic: TRUE
[cmake] -- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR)
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: C:/Users/sj2003/Desktop/videoCall/build
[visual-studio] is patched from D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat C:\Program Files (x86)\Windows Kits\10\bin\x64 to C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64 Windows SDK path

@sean-mcmanus
Copy link
Contributor

@shawn1j Yeah, can you check the C/C++: Log Diagnostics output with a C/C++ file active?

Or if you set C_Cpp.loggingLevel to "Debug" and check the "C/C++" logging for message "Custom configurations received:" that will show what receive from the CMake Tools extension after opening a file.

@shawn1j
Copy link
Author

shawn1j commented Jun 11, 2024

This is my c/c + + log output (because there is too much content, I stored it in the file):

c++ loging .txt

@shawn1j
Copy link
Author

shawn1j commented Jun 11, 2024

This is my cmake output

cmake-build-output

@sean-mcmanus
Copy link
Contributor

@shawn1j Your logging indicates CMake Tools is not sending us any configuration info for the header files that are opened, i.e. it doesn't appear that you're configured correctl or it could be a CMake Tools issue.

@sean-mcmanus sean-mcmanus transferred this issue from microsoft/vscode-cpptools Jun 12, 2024
@v-frankwang
Copy link
Collaborator

@shawn1j Thank you for reporting this issue. Regarding this issue, we tried to reproduce this issue using a simple demo project however we were unable to reproduce this issue for you. In order to investigate further, please provide us with a simple demo project to reproduce the issue and we look forward to your feedback.

@shawn1j
Copy link
Author

shawn1j commented Jun 14, 2024

Of course, here's my case, and it's very simple.

image

CMakeLists.txt

cmake_minimum_required(VERSION 3.10)

project(demo LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

add_executable(demo main.cpp )

main.cpp

#include <iostream>

int main(int argc, char **argv)
{
    std::cout << "Hello World" << std::endl;
  
    return 0;
}

The following is the output of cmake-tools, because c/ C ++ output too much information, I put it in the c_cpp.logging.txt file.
c_cpp.logging.txt

[proc] Executing command: D:\QT6\Tools\CMake_64\bin\cmake.exe --version
[proc] Executing command: D:\QT6\Tools\CMake_64\bin\cmake.exe -E capabilities
[variant] Loaded new set of variants
[kit] Successfully loaded 9 kits from C:\Users\sj2003\AppData\Local\CMakeTools\cmake-tools-kits.json
[proc] Executing command: chcp
[visual-studio] Patch Windows SDK path from C:\Program Files (x86)\Windows Kits\10\bin\x64 to C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64 for D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat
[main] Configuring project: src 
[proc] Executing command: D:\QT6\Tools\CMake_64\bin\cmake.exe --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -SC:/Users/sj2003/Desktop/demo/src -Bc:/Users/sj2003/Desktop/demo/src/build -G "Visual Studio 17 2022" -T host=x64 -A x64
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
[cmake] -- The CXX compiler identification is MSVC 19.40.33811.0
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: D:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.40.33807/bin/Hostx64/x64/cl.exe - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: C:/Users/sj2003/Desktop/demo/src/build
[visual-studio] Patch Windows SDK path from C:\Program Files (x86)\Windows Kits\10\bin\x64 to C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64 for D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat

Environment

  • OS and Version: windows 10 x64
  • VS Code Version: 1.90
  • C/C++ Extension Version: 1.20.5
  • CMake Version: 3.24.2
  • Visual Studio 2022 Version: v17.10.1

@v-frankwang
Copy link
Collaborator

v-frankwang commented Jun 19, 2024

@shawn1j I'm very sorry, I don't get this error with the code you provided, can you give me some advice?
image

@shawn1j
Copy link
Author

shawn1j commented Jun 21, 2024

Sorry to keep you waiting, I tried to use the latest version of cmake (version 3.29.6). After my testing, I found that when I used Visual Studio 2022 Developer Command Prompt v17.10.1 to launch vs code, vs code intellisense will work properly. This did not work with cmake (version 3.24.2), which I used earlier.
noerr

Here is the effect of starting vs code without Visual Studio 2022 Developer Command Prompt v17.10.1.
err

I wonder if this has anything to do with my computer environment. can you give me some advice?

@gcampbell-msft gcampbell-msft added this to the Backlog milestone Jun 25, 2024
@v-frankwang
Copy link
Collaborator

@shawn1j When I start vscode without Visual Studio 2022 Developer Command Prompt I get a generator not found, which should be normal because my generator is installed by installing VS and not separately, but I still can't reproduce the problem you described.
image

@gcampbell-msft
Copy link
Collaborator

For now, closing since user has a workaround and we weren't able to reproduce.

@gcampbell-msft gcampbell-msft closed this as not planned Won't fix, can't repro, duplicate, stale Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more info needed More info is needed from the community for us to properly triage and investigate.
Projects
Status: Completed
Development

No branches or pull requests

4 participants