[SOLVED]
Environment used:
- Windows 10 Enterprise, Version 10.0.19042
- Visual Studio Code, 1.54.3
- C/C++ Extension for Visual Studio Code, Version 1.2.2: February 25, 2021
- MinGW-w64 8.0.0
(I'm trying also WinLibs package with GCC 10.2.0 + LLVM/Clang/LLD/LLDB 11.0.0 + MinGW-w64 8.0.0)
Briefly, the problem is:
When I try to #include <dirent.h>, it is failed with the error: cannot open source file "dirent.h",
BUT #include "C:\Program Files\mingw-w64\mingw64\x86_64-w64-mingw32\include\dirent.h" to the file is working.
Screenshots of two cases are:
(sorry, I am not allowed to embed images yet, please open the links to the screenshots):
#include <dirent.h> -> failed
#include "C:\Program Files\mingw-w64\mingw64\x86_64-w64-mingw32\include\dirent.h" -> included, no errors
If include the file by the absolute path specified, the code is compiled and working.
Strange thing is that nearly placed direct.h header under the "C:\Program Files\mingw-w64\mingw64\x86_64-w64-mingw32\include" directory may be included with no specifying the absolute path. IntelliSense helps to include it: #include <direct.h>
My config files must be well-configured, since compilation and GDB debugging are working well.
I have two configurations: GCC and Win32 (MSVC compiler).
c_cpp_properties.json
{
"configurations": [
{
"name": "GCC",
"includePath": [
"C:\\Program Files\\mingw-w64\\mingw64\\x86_64-w64-mingw32\\include\\**",
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\Program Files\\mingw-w64\\mingw64\\bin\\g++.exe",
//"compilerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64"
},
{
"name": "Win32",
...
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
Variations of "includePath": ["C:\Program Files\mingw-w64\mingw64\x86_64-w64-mingw32\include**"] doesn't help (without * symbols at all or with one symbol). direct.h can be found without adding includePath values. I read somewhere that compilerPath makes environment asking the compiler about headers available. Also, I tried to change "cStandard": "c11" to other values: "gcc11", for example. It doesn't help.
I also tried to set the value of C_Cpp.default.includePath in workspace.codeworkspace file:
{
"folders": [
{
"path": "."
}
],
"settings": {
//"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
"C_Cpp.default.includePath": ["C:\\Program Files\\mingw-w64\\mingw64\\x86_64-w64-mingw32\\include"]
},
}
tasks.json:
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\Program Files\\mingw-w64\\mingw64\\bin\\g++.exe",
// "command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"args": [
// Add debug info (-g option) to the object file (files) and link to exe (-o option)
"-g",
"${fileDirname}\\**.c",
// "${fileDirname}\\**.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
],
"options": {
//"cwd": "${workspaceFolder}"
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: \"C:\\Program Files\\mingw-w64\\mingw64\\bin\\g++.exe\""
//"detail": "compiler: \"C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe\""
}
Code of C language which uses dirent.h is simple (again, it is compiled successfully if the absolute path is specified, so it must not be related to the problem, just in case):
#include <stdio.h>
#include "C:\\Program Files\\mingw-w64\\mingw64\\x86_64-w64-mingw32\\include\\dirent.h"
int main(int argc, char const *argv[])
{
DIR *dir1;
struct dirent *dirEntry;
dir1 = opendir(".");
if (dir1)
{
while ((dirEntry = readdir(dir1)) != NULL)
{
printf("%s\n", dirEntry->d_name);
}
closedir(dir1);
}
getchar();
}
PATH environment variable is set to the GCC compiler's path: PATH variable -> GCC compiler path
Could anyone help with it please? Or give any information what may be wrong? Why direct.h can be found correctly, but dirent.h is not? (and other headers also)
Thank you for any help and information.