方法一、
1、把要添加的.c和.h文件复制到c++程序目录中。
2、把.c文件改为.cpp文件
(预编译头可用,可不用)
3、把.cpp 和 .h文件都添加到该项目中 就可以使用了
ps:
直接Add files也行;
copy的时候如果.c 和 .h文件不在项目root目录里,则在项目-右键属性-配置属性-VC++目录,在包含目录中添加.c 和 .h的路径
方法二、
1、
项目配置不使用预编译头
-
In the Solution Explorer pane of the project, right-click the project name, and then click Properties.
-
In the left pane, click the C/C++ folder.
-
Click the Precompiled Headers node.
-
In the right pane, click Create/Use Precompiled Header, and then click Not Using Precompiled Headers.
2、.c文件加载到程序需中
3、把c语言
函数的声明用extern "C"{};
最好的写法是:
//------test.h----------
#ifdef __cplusplus
extern "C" {
#endif
//c语言函数声明写在这
#ifdef __cplusplus
}
#endif
//------test.c ------------
#ifdef __cplusplus
extern "C" {
#endif
#include "test.h"
//.c文件内容
#ifdef __cplusplus
}
#endif
========================================
h文件:
编译即可~