Introduce. H,. lib and DLL, And. cpp in the project.
1. Introduction of. h
Solution 1: Copy XX. H to the project directory
Solution 2: In more common cases, create an include directory elsewhere, set the project environment configuration, and point to the directory, as shown below:
Configure project properties: C/C ++ General additional include directory Add:... \ .. \ include
(If there are multiple projects, if the same. h file is referenced)
Now, you can declare class objects in the. h file, but you cannot use the methods.
Call a method
Compilation error:
Error 1 error lnk2001: external symbol _ xx. OBJ that cannot be parsed
Error 2 fatal error lnk1120: 1 external command that cannot be parsed XX. EXE 1
Note that the error is "Link", that is, the compilation is completed and there is no syntax error. When the Lib library is connected, an error is returned.
2. Introduction of the. Lib File
Introduction Method:
Project property linker input additional dependency XX. Lib
Compile:
Error 1 fatal error lnk1104: the file "XX. lib" cannot be opened"
Solution 1: Bake lib to the project directory
Solution 2: Copy lib to the \ lib directory and set:
Project property linker General additional library directory... \ .. \ Lib
F5 run
Pop-up error:
XX. dll
3. dll library Introduction
This time it should be easy to copy XX. DLL to the project directory.
To run the program under debug, copy XX. DLL to the DEBUG directory.
4. Introduction of CPP files
Assume that several projects in a project have some general modules (defined as independent. H and. CPP file). These general modules can be put in a public directory (common directory), which is introduced by everyone.
Usage: Configure project properties: C/C ++ General add include directory Add: .. \ common (add sub-directories if any)
At the same time, introduce the. h and. cpp files in the project. Note: After the import, it will be seen in the project file directory, but the file is still in the common directory and does not exist locally.
The purpose of the above settings is to put the additional resources, whether it is. H, Lib, or DLL, into another public directory as much as possible, rather than copying them under this project. Because there may be other projects that need to be referenced, put them in a public directory for convenient management.
The following describes the practices of various resources:
. H can be stored in a public directory without being copied to a local directory. You can directly # include "" without importing a. h file into the project ""
. Lib can be stored in a public directory without being copied to a local directory.
. DLL needs to be copied locally. If the program is compiled using debug, copy the program to debug.
. Cpp can be put in a public directory without being copied to a local directory.