Lib,dll differences and how to add Lib,dll in VS

Source: Internet
Author: User

1. Load the lib/header file

There are two ways of doing this:

(1) for the current project

1 Step One: Item--Properties->c/c++-> General , additional Include directories (browse. h file path) Add include file 2 Second step: Project--Properties->c/c++ Add-on dependency (write Lib name), linker--, input to the library file 3 project, Properties---  Additional Dependencies   
4 Step three: Add #include <gtest/gtest.h> (note the path to the file) before you want to use the CPP file

(This step can also show the call #pragma comment (lib, "***.lib") in the code.)
(if not added, connection error: unresolved external symbols)

(2) Applies to all items, and is set up so that no re-setup is required even if the new project is rebuilt.

1 for:(select Include files), add the . h path 2for:(Select library files), add a Lib path

(These paths only tell the compiler how to find the file, not the file that was added to the project.)
(if not set, compile error: Cannot open * * * file).

2.Load DLL

Copy the DLL file to the project debug file (if not copy, compile link without error, run Error: unable to find ***.dll)

the difference between 3.DLL and Lib files

Lib is a binary file that resembles a DLL for other programs to invoke. The difference between Lib and DLL is that DLLs are required at runtime, and Lib is required at compile time.

There are two kinds of libraries:
One is that Lib contains the information (ingress) of the DLL file in which the function resides and the location of the function in the file, which is provided by the DLL that is loaded in the process space by the runtime, called the dynamic link library.
One is that Lib contains the function code itself, which is added directly to the program at compile time, called static link library.

There are two ways to link:
Dynamic linking uses a dynamic-link library that allows executable modules (. dll files or. exe files) to contain only the information required to locate the executable code of a DLL function at run time.
Static linking uses the static link library, which obtains all referenced functions from the static link library lib and places the library with the code in the executable file.

The differences between Lib and DLL are as follows:
(1) Lib is used at compile time, DLL is used at runtime. If you want to complete the compilation of the source code, you only need lib, if you want to make a dynamically linked program run, you only need the DLL.
(2) If there is a DLL file, then Lib is generally some index information, log the function of the DLL's entry and location, DLL is the specific content of the function, if only the Lib file, then the Lib file is statically compiled, the index and implementation are in it. Using a statically compiled Lib file, you do not need to hang the dynamic library when you run the program, the disadvantage is that the application is larger, and the flexibility of the dynamic library is lost, and the new version is released when the new application is published.
(3) In case of dynamic link, there are two files: one is lib file and one is DLL file. Lib contains the name and location of the function exported by the DLL, the DLL contains the actual functions and data, and the application uses the Lib file to link to the DLL file. In the application's executable file, it is not the called function code, but the address of the corresponding function code in the DLL, thus saving memory resources. DLL and LIB files must be released with the application or the application will produce an error. If you do not want to use the Lib file or no Lib file, you can use the WIN32 API function LoadLibrary, GetProcAddress load.

There are two files to be aware of using Lib:
(1). h header file containing class or symbol prototypes or data structures that describe the output in Lib. When the application calls Lib, it needs to include the file in the application's source file.
(2). LIB file, slightly.

There are three files to be aware of using DLLs:
(1). h header file containing the. h file that describes the output class or symbol prototype or data structure in the DLL. When an application calls a DLL, it needs to include the file in the application's source file.
(2). LIB file is a file generated by a DLL after it is compiled and successfully linked, and it is necessary to introduce the file into the application when other applications call the DLL, otherwise an error is generated. If you do not want to use the Lib file or no Lib file, you can use the WIN32 API function LoadLibrary, GetProcAddress load.
(3). dll file, the real executable, after the successful development of the application at the time of publishing, only the. exe file and the. dll file are required, and the. lib file and the. h header file are not required

Lib,dll differences and how to add Lib,dll in VS

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: info-contact@alibabacloud.com 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.