C++ 包孕非系统的C头文件,不知道这样写为什么错了?
C++ 包含非系统的C头文件,不知道这样写为什么错了??
//pro1.h
#ifdef _cplusplus
extern "C"
{
#endif
void PrintMessage();
#ifdef _cplusplus
};
#endif
//pro1.c
#include <stdio.h>
#include "pro1.h"
void PrintMessage()
{
printf("%s","hello world !");
}
//main.cpp
#include "pro1.h"
int main()
{
PrintMessage();
return 0;
}
main.obj : error LNK2001: unresolved external symbol "void __cdecl PrintMessage(void)" (?PrintMessage@@YAXXZ)
Debug/pro1.exe : fatal error LNK1120: 1 unresolved externals
求原因,求解释??
------解决方案--------------------
#ifdef __cplusplus
extern "C"
{
#endif
void PrintMessage();
#ifdef __cplusplus
};
#endif
两个下划线
//pro1.h
#ifdef _cplusplus
extern "C"
{
#endif
void PrintMessage();
#ifdef _cplusplus
};
#endif
//pro1.c
#include <stdio.h>
#include "pro1.h"
void PrintMessage()
{
printf("%s","hello world !");
}
//main.cpp
#include "pro1.h"
int main()
{
PrintMessage();
return 0;
}
main.obj : error LNK2001: unresolved external symbol "void __cdecl PrintMessage(void)" (?PrintMessage@@YAXXZ)
Debug/pro1.exe : fatal error LNK1120: 1 unresolved externals
求原因,求解释??
c++
------解决方案--------------------
#ifdef __cplusplus
extern "C"
{
#endif
void PrintMessage();
#ifdef __cplusplus
};
#endif
两个下划线