method one,
1. Copy the .c and .h files to be added to the c++ program directory.
2. Change the .c file to the .cpp file
(precompiled header is available, but not necessary)
3. Add the .cpp and .h files to the project to use
ps:
Add files directly also works;
If the .c and .h files are not in the root directory of the project when copying, add the paths of .c and .h in the include directory in the project-right-click properties-configuration properties-VC++ directory
Method Two,
1. The
project configuration does not use precompiled headers
-
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. Load the .c file into the program
3, the c language
function declaration
with extern "C" {};
The best way to write is:
//------test.h----------
#ifdef __cplusplus
extern "C" {
#endif
//c language function declaration is written here
#ifdef __cplusplus
}
#endif
//------test.c ------------
#ifdef __cplusplus
extern "C" {
#endif
#include "test.h"
//.c file content
#ifdef __cplusplus
}
#endif
========================================
h file:
Just compile~