我正在使用VS2008。我收到以下错误。
BUILD: [02:0000000295:ERRORE] c:\wince700\platform\am33x_bsp\src\bootloader\bootpart\bootpart_e.cpp(61) : error C2732: linkage specification contradicts earlier specification for 'SdhcInitialize' {log="C:\WINCE700\platform\AM33X_BSP\SRC\BOOTLOADER\bldsys.log(103)"}
BUILD: [02:0000000297:ERRORE] NMAKE : fatal error U1077: 'C:\WINCE700\sdk\bin\i386\ARM\cl.EXE' : return code '0x2' {log="C:\WINCE700\platform\AM33X_BSP\SRC\BOOTLOADER\bldsys.log(104)"}
BUILD: [02:0000000299:ERRORE] clean TargetCompilePass -nologo BUILDMSG=Stop. BUILDROOT=C:\WINCE700\platform\AM33X_BSP CLEANBUILD=1 NOLINK=1 NOPASS0=1 failed - rc = 2. {log="C:\WINCE700\platform\AM33X_BSP\SRC\BOOTLOADER\bldsys.log(105)"}
文件_1.cpp
extern "C"
{
// some extern declarations
extern void SdhcInitialize(DWORD slot);
}
文件_2.c
void SdhcInitialize(DWORD slot)
{
//some code
}
请指导我如何解决。
原文由 Gomu 发布,翻译遵循 CC BY-SA 4.0 许可协议
我猜你有一个包含
SdhcInitialize()
函数原型的头文件,并且该头文件是为 C 程序使用而编写的。因此,例如,头文件可能包含类似于以下行的内容:没有包含在
extern "C" {}
块中(因为标头用于 C 程序)。此外,我怀疑这个标头直接或间接地被
file_1.cpp
这意味着如果不做一些额外的工作,头文件就不能包含在 C++ 程序中,否则 C++ 程序会将声明视为意味着
SdhcInitialize()
具有 C++ 链接。你有两种合理的方法来解决这个问题:
这样,C++ 文件的声明将包含在
extern "C"
链接块中,而 C 程序将看不到extern "C"
位(否则会混淆 C 编译器)。我认为可以提出一个论点,即所有 C 标头都应包含类似这些行的内容,以便 C 函数可以被 C++ 程序轻松使用。