我已经开始在我的嵌入式 C 项目中使用 VSC,在 Mac 上使用 gcc for ARM。在 c_cpp_properties.json
中设置包含路径,我的大部分#includes
现在正在工作。然而,像这样的一行:
uint32_t m_ttff_seconds = 0;
产生红色波浪下划线和错误:
variable uint32_t is not a type name
有问题的源文件包括 stdint:
#include <stdint.h>
和 includePath
包括:
"${HOME}/dev/gcc-arm-none-eabi-4_9-2015q3/lib/gcc/arm-none-eabi/4.9.3/include"
和:
"intelliSenseMode": "clang-x64"
(唯一的其他选项是 msvc-x64
)。
当我使用 make 和 gcc 时,代码库编译得很好。如何在 uint32_t
中显示 C/C++ 扩展是吗?
编辑:
stdint.h
看起来像这样:
#ifndef _GCC_WRAP_STDINT_H
#if __STDC_HOSTED__
# if defined __cplusplus && __cplusplus >= 201103L
# undef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS
# undef __STDC_CONSTANT_MACROS
# define __STDC_CONSTANT_MACROS
# endif
# include_next <stdint.h>
#else
# include "stdint-gcc.h"
#endif
#define _GCC_WRAP_STDINT_H
#endif
和stdint-gcc.h
包含:
/* 7.8.1.1 Exact-width integer types */
#ifdef __INT8_TYPE__
typedef __INT8_TYPE__ int8_t;
#endif
#ifdef __INT16_TYPE__
typedef __INT16_TYPE__ int16_t;
#endif
#ifdef __INT32_TYPE__
typedef __INT32_TYPE__ int32_t;
#endif
#ifdef __INT64_TYPE__
typedef __INT64_TYPE__ int64_t;
#endif
#ifdef __UINT8_TYPE__
typedef __UINT8_TYPE__ uint8_t;
#endif
#ifdef __UINT16_TYPE__
typedef __UINT16_TYPE__ uint16_t;
#endif
#ifdef __UINT32_TYPE__
typedef __UINT32_TYPE__ uint32_t;
#endif
#ifdef __UINT64_TYPE__
typedef __UINT64_TYPE__ uint64_t;
#endif
这表明 __UINT32_TYPE__
在 VSC 解析我的代码时未定义,但在我使用 make 和 gcc 构建时定义。
编辑:
按照@mbmcavoy 的回答,我包括了我的 c_cpp_properties.json
文件在这里:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${HOME}/dev/gcc-arm-none-eabi-4_9-2015q3/lib/gcc/arm-none-eabi/4.9.3/include",
"${HOME}/dev/nRF5_SDK_14.0.0_3bcc1f7/components/libraries/util",
"${HOME}/dev/nRF5_SDK_14.0.0_3bcc1f7/config",
[many more of these omitted]
"${HOME}/dev/wisol_SDK_SFM20Rx_master/development/sigfox_cfg2/source",
"${workspaceRoot}"
],
"browse": {
"path": [
"${HOME}/dev/gcc-arm-none-eabi-4_9-2015q3/lib/gcc/arm-none-eabi/4.9.3/include",
"${HOME}/dev/nRF5_SDK_14.0.0_3bcc1f7/components/libraries/util",
"${HOME}/dev/nRF5_SDK_14.0.0_3bcc1f7/config",
[many more of these omitted]
"${workspaceRoot}"
],
"databaseFilename": "${workspaceRoot}/.vscode/browse.vc.db"
},
"intelliSenseMode": "clang-x64",
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"defines": [
"__UINT_LEAST16_MAX__=65535",
"__UINT_LEAST8_TYPE__=unsigned char",
"__UINT8_MAX__=255",
"__UINT_FAST64_MAX__=18446744073709551615ULL",
"__UINT_FAST8_MAX__=4294967295U",
"__UINT_LEAST64_MAX__=18446744073709551615ULL",
"__UINT_LEAST8_MAX__=255",
"__UINTMAX_TYPE__=long long unsigned int",
"__UINT32_MAX__=4294967295UL",
"__UINT16_C(c)=c",
"__UINT16_MAX__=65535",
"__UINT8_TYPE__=unsigned char",
"__UINT64_C(c)=c ## ULL",
"__UINT_LEAST16_TYPE__=short unsigned int",
"__UINT64_MAX__=18446744073709551615ULL",
"__UINTMAX_C(c)=c ## ULL",
"__UINT_FAST32_MAX__=4294967295U",
"__UINT_LEAST64_TYPE__=long long unsigned int",
"__UINT_FAST16_TYPE__=unsigned int",
"__UINT_LEAST32_MAX__=4294967295UL",
"__UINT16_TYPE__=short unsigned int",
"__UINTPTR_MAX__=4294967295U",
"__UINT_FAST64_TYPE__=long long unsigned int",
"__UINT_LEAST32_TYPE__=long unsigned int",
"__UINT8_C(c)=c",
"__UINT64_TYPE__=long long unsigned int",
"__UINT32_C(c)=c ## UL",
"__UINT_FAST32_TYPE__=unsigned int",
"__UINTMAX_MAX__=18446744073709551615ULL",
"__UINT32_TYPE__=long unsigned int",
"__UINTPTR_TYPE__=unsigned int",
"__UINT_FAST16_MAX__=4294967295U",
"__UINT_FAST8_TYPE__=unsigned int"
]
}
],
"version": 3
}
编辑:
深入挖掘后,我发现 gcc-arm-none-eabi-4_9-2015q3/lib/gcc/arm-none-eabi/4.9.3/include/stdint.h
有__STDC_HOSTED__
定义,因此 stdint-gcc.h
实际上并没有被包括在内。相反,该 header 执行“include_next <stdint.h>
”,它找到 gcc-arm-none-eabi-4_9-2015q3/arm-none-eabi/include/stdint.h
.我仍然看不到 unint32_t 的定义位置,无论是针对 gcc 和 make 还是针对 VSC。
最佳答案
在尝试了所有建议的解决方案都没有效果后,我认为 uint32_t 问题是一个错误。
要解决 VSCode 中烦人的警告,只需在#include 部分后添加以下行:
typedef __uint32_t uint32_t;
通过在单个文件中执行一次,它修复了我的 VSCode 警告并仍然可以编译。
关于Visual Studio Code、gcc、Mac 的 C/C++ 扩展 : "variable uint32_t is not a type name",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45701187/