我已经开始在Mac上使用VSC为我的嵌入式C项目使用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
这表明当VSC解析我的代码时,没有定义__UINT32_TYPE__
,但是当我使用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
实际上并未被包括在内。相反,该标题执行“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警告并仍然编译。
我已经能够在我的机器(Windows)上解决这个问题,包括三个步骤:
问题是正确的,当它指出“这表明在VSC解析我的代码时没有定义__UINT32_TYPE__
,但它是在我使用make和gcc构建时定义的。” ARM交叉编译器有许多未包含在clang-x64解析器中的内置定义。
首先,使用-dM -E
选项找出gcc编译器定义的定义。在Windows上,我能够使用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)
其次,将定义添加到c_cpp_properties.json
文件中。请注意,在#define设置值的位置,您需要在此处使用=
符号。 (您可能只需要根据需要添加单个定义,但我使用Excel根据需要对其进行格式化和排序。第一个定义用于我的项目,与我的Makefile中的定义相匹配。)
"defines": [
"STM32F415xx",
"USE_FULL_LL_DRIVER",
"__USES_INITFINI__",
"__ACCUM_EPSILON__=0x1P-15K",
"__ACCUM_FBIT__=15",
(...)
"__UINT32_TYPE__=long unsigned int",
(etc.)
在对单个定义进行一些实验之后,我可以看到定义在stdint-gcc.h
中被处理,类型的任何使用仍然产生错误。我在我的c_cpp_properties.json
文件中意识到我有"databaseFilename": ""
这用于“生成的符号数据库”,但未正确配置。我把它设置为:
"databaseFilename": "${workspaceRoot}/.vscode/browse.vc.db"
退出并重新启动Visual Studio代码后,声明不会导致错误,当将鼠标悬停在变量上时,它会显示相应的类型。