Method of adding .ch in Visual Studio project C++ program

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
  1. In the Solution Explorer pane of the project, right-click the project name, and then click Properties.

  2. In the left pane, click the C/C++ folder.

  3. Click the Precompiled Headers node.

  4. 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:
 
Method of adding .ch in C++ program
 
C file:
Method of adding .ch in C++ program
 
Path addition:

Method of adding .ch in C++ program
 
File addition:
Method of adding .ch in C++ program

 
Just compile~

Guess you like

Origin blog.csdn.net/lm393485/article/details/88892361
Recommended