0

I have problem with visual studio code and fmt library for c++. I get the library to work but my intellisense does not show/fill fmt/os.h header's functions when writing, And the reason for that is these lines in the os.h header

I use win10 and mingw g++ and at the bottom is my tasks.json

#if (FMT_HAS_INCLUDE(<fcntl.h>) || defined(__APPLE__) || \
     defined(__linux__)) &&                              \
    (!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP))
#  include <fcntl.h>  // for O_RDONLY
#  define FMT_USE_FCNTL 1
#else
#  define FMT_USE_FCNTL 0
#endif

So #define FMT_USE_FCNTL 0 causes parts of the header to be not recognized by the intellisense (it "comments" off parts of the header at the line 149). I am total beginner in this, so I have no idea what is going on. Is this something I could flag in cmake when building fmt, or what? Weird thing for me is that everything seems to work great fmt::output_file etc. works, but intellisense just does not recognize those functions. I have tried googling this, but since my knowledge is limited I don't even know where the problem could be.

Also just for example, this example code from fmt github below runs, but I can't auto fill the output_file command, and intellisense shows error on the output_file function saying that namespace "fmt" does not have member "output_file".

#include <fmt/os.h>

int main() {
  auto out = fmt::output_file("guide.txt");
  out.print("Don't {}", "Panic");
}
{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "build",
            "command": "g++.exe",
            "args": [
                "-Wall",
                "-g",
                "-std=c++2a",
                "${file}",
                "${fileDirname}\\src\\*.cpp",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                // fmt includes and links
                "-I",
                "C:\\Users\\user\\Documents\\1links\\Git\\Git\\cpp_libs\\fmt\\include",
                "-I",
                "C:\\Users\\user\\Documents\\1links\\Git\\Git\\cpp_libs\\fmt\\src",
                "C:\\Users\\user\\Documents\\1links\\Git\\Git\\cpp_libs\\fmt\\Build\\libfmt.a",
                // library files needed to make the libraries work
            ],
            "options": {
                "cwd": "C:/MinGW/mingw32/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

Also here is my c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Mingw",
            "includePath": [
                "${default}",
                "C:\\Users\\user\\Documents\\1links\\Git\\Git\\cpp_libs\\fmt\\include"
            ],
            "windowsSdkVersion": "10.0.18362.0",
            "compilerPath": "C:\\MinGW\\bin\\g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++20",
            "intelliSenseMode": "gcc-x86"
        }
    ],
    "version": 4
}

Thank you for your time.

  • But why does the code still work? it seems to be only the intellisense part that for some reason does not work. And if I bypass that FMT_USE_FCNTL thing I get the intellisense to work, but that cannot be the correct way to do things? Thank you for your answer. – Märkäkorva Jan 02 '21 at 17:16
  • 2
    Intellisense is a sort of real-time compiler separate from the actual compiler. It's real fast, but it's not rigorous enough to catch all of the cases. Maybe you've got a configuration issue that can be fixed, or maybe it missed a case. – user4581301 Jan 02 '21 at 17:22
  • I haven't configured my intellisense, other than added library paths for it to find the libraries, and that has worked with wxwidgets which I have used earlier. Is there some obvious places to check you know of (in the settings of the intellisense)? – Märkäkorva Jan 02 '21 at 17:30
  • `c_cpp_properties.json` is the file https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference – drescherjm Jan 02 '21 at 17:35
  • My guess would that Intellisense might not know how to handle `FMT_HAS_INCLUDE(...)`. If you replace that part with `1`, does Intellisense works? – Phil1970 Jan 02 '21 at 17:48
  • @Phil1970 Yes, intellisense works if I do that. – Märkäkorva Jan 02 '21 at 18:14
  • @drescherjm I added my c_cpp_properties.json to the original message. – Märkäkorva Jan 02 '21 at 18:16

0 Answers0