【发布时间】:2017-12-31 04:34:12
【问题描述】:
美好的一天
我正在尝试在 C++11 项目中使用 C SD 驱动程序/文件系统库 (Keil MDK)。它是由 Keil MDK 5.23 中的包管理器添加的。我正在使用 ARMCC 5.06u4 进行编译
我收到警告 class "_ARM_MCI_STATUS" 没有合适的复制构造函数”,这很奇怪,因为它声明的标头有 extern "C" {。
默认情况下,包没有将其设置为 C 或 C++ 的选项,但我已手动将文件添加为 C 文件。还是有问题。
结构在extern "C" { 中被声明为:
typedef volatile struct _ARM_MCI_STATUS {
uint32_t command_active : 1; ///< Command active flag
uint32_t command_timeout : 1; ///< Command timeout flag (cleared on start of next command)
uint32_t command_error : 1; ///< Command error flag (cleared on start of next command)
uint32_t transfer_active : 1; ///< Transfer active flag
uint32_t transfer_timeout : 1; ///< Transfer timeout flag (cleared on start of next command)
uint32_t transfer_error : 1; ///< Transfer error flag (cleared on start of next command)
uint32_t sdio_interrupt : 1; ///< SD I/O Interrupt flag (cleared on start of monitoring)
uint32_t ccs : 1; ///< CCS flag (cleared on start of next command)
uint32_t reserved : 24;
} ARM_MCI_STATUS;
结构体在以下位置返回时出现问题:
static ARM_MCI_STATUS GetStatus (MCI_RESOURCES *mci) {
return mci->info->status;
}
其中status 被声明为ARM_MCI_STATUS status;。我不明白为什么它应该是一个问题。
如果我在没有 --cpp 的情况下编译,那么它编译没有问题。
有什么建议吗?
【问题讨论】:
-
仅仅因为它被标记为
extern "C"并不意味着它绕过了C++规则。 -
结构和类型名从不需要
extern "C",只有函数需要。它的作用基本上是阻止name-mangling 的功能。 -
@RickAstley 我正在收集这一点,尽管我知道/不知道特定的 C++ 规则需要基本 C 位字段的复制构造函数。你知道吗?
-
至于解决你的问题的方法,当你说你“手动将文件添加为C文件”时,你的意思是你给它起了一个带有
.c后缀的名字吗?因为如果你想将它构建为 C 源文件,那就是你需要做的。 -
@Someprogrammerdude 该库是一个只有 .c/h 的 C 库。在 Keil 中,我将文件类型设置为“C 源代码”。尽管全局“--cpp”标志使所有文件都解释为 C++。这似乎是问题所在。