0

我对 c++ 的Visual Studio 代码fmt库有疑问。我让库工作,但我的智能感知在编写时没有显示/填充fmt/os.h标头的函数,原因是 os.h 标头中的这些行

我使用win10和mingw g++,底部是我的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

因此 #define FMT_USE_FCNTL 0 导致智能感知无法识别部分标题(它在第 149 行“注释”掉部分标题)。我是这方面的初学者,所以我不知道发生了什么。这是我在构建 fmt 时可以在 cmake 中标记的东西,还是什么?对我来说奇怪的是,一切似乎都很好 fmt::output_file 等工作,但智能感知只是无法识别这些功能。我试过用谷歌搜索,但由于我的知识有限,我什至不知道问题出在哪里。

也只是例如,下面的 fmt github 的这个示例代码运行,但我无法自动填充 output_file 命令,并且智能感知在 output_file 函数上显示错误,说命名空间“fmt”没有成员“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
            }
        }
    ]
}

这也是我的 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
}

感谢您的时间。

4

0 回答 0