【问题标题】:How can I teach Visual Studio Code about __fp16?我如何教 Visual Studio Code 关于 __fp16?
【发布时间】:2020-12-07 17:10:30
【问题描述】:

我有一个使用 arm-none-eabi 编译器编译的 Cortex-M4F 微控制器的 makefile 项目,并且我对一些浮点数使用 __fp16 存储类型。我正在使用 Visual Studio Code 来编辑代码,并使用 makefile 进行编译。

我的代码编译正常,但 Visual Studio Code 无法识别 __fp16 存储类型。

我正在使用 c_cpp_properties.json 来配置编译器和一个 compile_commands.json。

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "${workspaceFolder}/../**",
                "/usr/local/FreeRTOSv10.2.0/FreeRTOS/**"
            ],
            "defines": [
                "DEBUG=1",
                "FIRMWARE_VERSION=\"DUMMY\""
            ],
            "compilerPath": "/usr/local/bin/gcc-arm-none-eabi-8-2018-q4-major/bin/arm-none-eabi-gcc",
            "compilerArgs": [
                "-mcpu=cortex-m4",
                "-march=armv7+fp",
                "-mfpu=fpv4-sp-d16",
                "-mfloat-abi=hard",
                "-mfp16-format=ieee"
            ],
            "intelliSenseMode": "gcc-arm",
            "cStandard": "c11",
            "compileCommands": "${workspaceFolder}/compile_commands.json"
        }
    ],
    "version": 4
}

如何向 Visual Studio Code 教授 __fp16 存储类型?我认为它会发现带有 compilerArgs 设置和 -mfp16-format=ieee 参数的类型,但它似乎没有什么不同(我在这里尝试了各种组合......)。

【问题讨论】:

    标签: c visual-studio-code arm intellisense


    【解决方案1】:

    这看起来像是 Intellisense 错误。 Intellisense 会在您键入时快速编译代码,只是为了捕捉简单的错误。但这不是完整的 GCC 编译器。 Intellisense 不生成 ARM 代码,它只是检查合法的 C++。

    您可以通过在 c_cpp_properties.json 中将 __fp16=float 添加到 defines 来欺骗 Intellisense。如果documentation 是正确的,那就是传递给实际的编译器,只是传递给 Intellisense。

    【讨论】:

    • 我试过了,但它不起作用。根据文档,这是因为我使用的是 compile_commands.json 文件,并且仅在没有 compile_commands 文件时才使用定义。
    • “它不起作用”?这意味着您的问题保持不变,即红色的 Intellisense 曲线表示 __fp16 未定义?
    • 是的,没错。根据您在文档中链接的页面,defines 仅在没有 compile_commands.json 时使用。我想我可以尝试不带 compile_commands.json....
    • @SolArnu:另一种方法是在您的代码中使用#ifdef __INTELLISENSE__ #define __fp16 float #endif。但我不确定该宏是否适用于 VS Code。
    • 该解决方法有效,并且至少对于 Visual Studio 来说似乎是一个记录在案的功能。 docs.microsoft.com/en-us/cpp/preprocessor/…
    猜你喜欢
    • 1970-01-01
    • 2021-10-23
    • 1970-01-01
    • 2020-11-09
    • 1970-01-01
    • 1970-01-01
    • 2021-01-07
    • 1970-01-01
    • 2019-02-28
    相关资源
    最近更新 更多