C++程序中添加.c.h的方法

方法一、
1、把要添加的.c和.h文件复制到c++程序目录中。
2、把.c文件改为.cpp文件
3、把.c.h文件都添加到该项目中 就可以使用了
方法二、
1、项目配置不使用预编译头
2、.c文件加载到程序需中
3、把c语言函数的声明用extern "C"{};中

现在最好的写法是:
//test.h
#ifdef __cplusplus
extern "C" {
#endif
//c语言函数声明写在这
#ifdef __cplusplus
}
#endif
//test.c
//.c开头出
#ifdef __cplusplus
extern "C" {
#endif
#include "test.h"
//.c文件内容
#ifdef __cplusplus
}
#endif
//.c文件结束

猜你喜欢

转载自blog.csdn.net/m0_37759974/article/details/80507929