C/C++ extension for Visual Studio Code, gcc, Mac: “variable uint32_t is not a type name”

后端 未结 2 2108
遇见更好的自我
遇见更好的自我 2021-01-06 22:42

I\'ve begun using VSC for my embedded C projects with gcc for ARM on a Mac. Having set up include paths in c_cpp_properties.json, most of my #includes

相关标签:
2条回答
  • 2021-01-06 22:57

    I have been able to resolve this on my machine (Windows), with three steps:

    1. Applying Compiler Defines to the C/C++ Extension

    The question is correct when it states "This suggests __UINT32_TYPE__ is NOT defined when VSC is parsing my code, but it IS defined when I build with make and gcc." The ARM cross-compiler has many built-in defines that are not included in the clang-x64 parser.

    First, find out defines your gcc compiler defines, with the -dM -E options. On Windows I was able to dump the output to a file with echo | arm-none-eabi-gcc -dM -E - > gcc-defines.txt

    #define __DBL_MIN_EXP__ (-1021)
    #define __HQ_FBIT__ 15
    #define __UINT_LEAST16_MAX__ 0xffff
    #define __ARM_SIZEOF_WCHAR_T 4
    #define __ATOMIC_ACQUIRE 2
    #define __SFRACT_IBIT__ 0
    #define __FLT_MIN__ 1.1754943508222875e-38F
    #define __GCC_IEC_559_COMPLEX 0
    (etc. - I have 344 defines)
    

    Second, add the defines to your c_cpp_properties.json file. Note that where the #define sets a value, you need to use an = sign here. (You could probably just add individual defines as you need them, but I used Excel to format them as needed and sort. The first defines are for my project, matching the defines in my Makefile.)

    "defines": [
        "STM32F415xx",
        "USE_FULL_LL_DRIVER",
        "__USES_INITFINI__",
        "__ACCUM_EPSILON__=0x1P-15K",
        "__ACCUM_FBIT__=15",
        (...)
        "__UINT32_TYPE__=long unsigned int",
        (etc.)
    
    1. Setting the Symbol Database

    After doing a few experiments with individual defines, I could see the define as being processed in stdint-gcc.h, any uses of the types still produced errors. I realized in my c_cpp_properties.json file that I had "databaseFilename": "" This is used for the "generated symbol database", but was not configured properly. I set it to:

    "databaseFilename": "${workspaceRoot}/.vscode/browse.vc.db"
    
    1. Restart Visual Studio Code

    After quitting and restarting Visual Studio Code, declarations do not result in the error, and when hovering over a variable, it shows the appropriate type.

    0 讨论(0)
  • 2021-01-06 22:59

    After trying all of the proposed solutions to no effect, I consider the uint32_t issue to be a bug.

    To solve the annoying warnings in VSCode, just add the following line after your #include section:

    typedef __uint32_t uint32_t;
    

    By doing this once in a single file, it fixes my VSCode warnings and still compiles.

    0 讨论(0)
提交回复
热议问题