VC ++ configuration confusions

Source: Internet
Author: User

If a third-party library file is used during development, such as in C #, for example, to access the SQLite database, we need to introduce the DLL file and related files into the project file, this operation is to add reference.

However, when using VC ++, it seems that it is not that simple, because when introducing a third-party, apart from DLL, there may also be Lib, hfile, and so on. Of course, there may be no DLL here, it is necessary to introduce DLL and Lib


. Dll is in yourProgramThe file that is connected during running, so it is a relatively small executable file format ,. DLL has other file formats such. OCX, etc. All. all DLL files are executable.

. Lib is the file that is connected when your program compiles the connection. Therefore, you must inform the compiler of where the Lib file is connected. In general, compared with dynamic connection files, lib files are also called static connection libraries. When youCodeWhen files are compiled into these formats, they cannot be changed later. To use the Lib file, you must:

1. Include a corresponding header file to inform the compiler of the specific content in the Lib file.
2. Set the Lib file to allow the compiler to find the compiled binary code.

If you want to separate a DLL file from your code to replace the static Connection Library, you still need a lib file. This lib file will be connected to a program to tell the operating system what DLL file you want to use during running. Generally, the LIB file contains the corresponding DLL file name and a sequence table that specifies the DLL output function entry. If you do not want to use the Lib file or do not have the Lib file, you can use Win32
API functions: loadlibrary and getprocaddress. In fact, we can
IDE opens the Lib file in binary format. In most cases, you will see the ASCII code format C ++ function or some function names for heavy-load operations.


In VC ++, we may encounter two types of libraries: Common DLL and library ending with Lib.

The full name of DLL is dynamic link library, which is used during running and dynamic loading of applications during running.

The LIB file is special and can be divided into two types based on whether a DLL file exists:

If a DLL file exists, Lib is generally an index that records the function entry and location in the DLL. The dll contains the specific content of the function. The application uses the Lib file to link to the DLL file, in the executable file of an application, the address of the corresponding function code in the DLL is not stored in the called function code, thus saving memory resources. DLL and Lib files must be released along with the application; otherwise, errors may occur in the application. If you do not want to use the Lib file or do not have the Lib file, you can use the Win32 API functions loadlibrary and getprocaddress for loading.

If only the Lib file is available, the Lib file is statically compiled. Such a file is usually called static Link Library, and the index and implementation are all in it. The static library does not need to be attached to the dynamic library when running the program. The disadvantage is that the application is large and the flexibility of the dynamic library is lost, only release new applications when releasing a new version.

Note the following two files when using Lib:
(1) The. h header file contains the class or symbol prototype or data structure described in Lib. When an application calls Lib, the file must be included in the application's source file.
(2). Lib file, omitted.

When using DLL, pay attention to three files:
(1). h header file, which contains a. h file indicating the output class or symbol prototype or data structure in DLL. When an application calls a DLL, the file must be included in the application's source file.
(2 ). the LIB file is generated after the DLL is compiled and linked successfully. It is used to introduce the file into the application when other applications call the DLL. Otherwise, an error occurs.If you do not want to use the Lib file or do not have the Lib file, you can use the Win32 API functions loadlibrary and getprocaddress to load the file (display the connection, whether to consider searching the DLL sequence ).
(32.16.dll file, which is a real executable file. Only the. exe file and. dll file are available when the application program behind the development is running, and the. Lib file and. h file are not required.

During configuration in VC ++, it is not necessary to introduce the header file, because this is required for both DLL and Lib. h file. the file in which H is located serves as the inclusion Directory, which is usually configured in the VC ++ directory option. You can specify the following directory types during VC ++ configuration.

Executable Directory Search for the Directory of the executable file. corresponds to the path environment variable.
include directory Search for directories containing files referenced in Source Code . corresponds to the include environment variable.
reference directory # using directive. "> Search for the Directory of the assembly and module (metadata) files referenced in the source code using the # using command. corresponds to the libpath environment variable.
library directory Search for the Directory of the Library (including the Runtime Library. corresponds to the lib environment variable.
Source directorySearch for the Directory of the source file for intelliisense.
Exclude directoryCheck that the directory is not searched when the dependency item is generated.

Now there is another problem. We know that C ++ is in progress. the H file is equivalent to a declaration file or metadata file, but the actually executed code is in the CPP file, only. the H file must not work, but also the library file. Otherwise, the "Link error" error is often encountered during running. This is because the Lib file is not set, add the required lib to the additional link library in the connector. Of course, you can also use

# Pragma comment (Lib, "liuyu. lib") to set

Another question is, where is the path of the Lib file?

There are several differences between them, and I don't quite understand them. I just paste the question as follows:

What is the difference between the C/C ++ include directory and the VC ++ include directory?
What is the difference between the General additional library directory of the connector and the VC ++ directory?
Additional dependency: indicates the input items, such as A. Lib file liuyu. Lib, which is added to the additional dependency. Your lib file is actually included. Equivalent to the "# pragma comment (Lib," liuyu. lib ")" Statement
Additional library Directory: the directory where the additional dependency is located. When # pragma comment (Lib, "liuyu. lib "); search for liuyu. the LIB path list contains this path.
But I still don't know the confusion above. I guess these configurations are the same. After my search and inquiry, I found a post. The search sequence is different, but the results are the same.
The connection is as follows:


The compiler searches for directories in the following order:

1. directories containing the source file.

2. Directories specified with the/I option, in the order that Cl encounters them.

3. Directories specified in the include environment variable.

The/I in order2 is set by C/C ++-> General-> additional include directories.

The include in order3 is set by VC ++ directories-> include directories.


Remember the order of searching DLL in the blog before, here I recommend another article:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.