OBJ, Lib, DLL, exe

Source: Internet
Author: User
Tags types of functions

Relationship between OBJ, Lib, DLL, and exe

Lib corresponds to DLL. Lib is the library file of the static Link Library, and DLL is the library file of the dynamic link library.

The so-called static is to extract the required content from the link and arrange it into your EXE file. Lib is no longer needed for running your EXE later.

The so-called dynamic is that when the EXE runs, it depends on the functions provided in the DLL. Without this DLL, your EXE cannot run.

Lib, DLL, and exe are all final target files and are final products. C/C ++Source code. SourceCodeThe transition from the final target file is the intermediate code obj. In fact, you cannot get the target file at one time because you need intermediate code. For example, an EXE requires many CPP files to be generated. The compiler can only compile one CPP file at a time. In this way, the compiler will compile a CPP into obj. When all required CPP files are compiled into OBJ, the compiler will link them to the required exe, if any obj is missing, the link of the EXE will fail.

1. OBJ stores the compiled code and data with a name. Therefore, an unsolved external symbol may occur during connection. After an EXE is connected, the name concept does not exist. Only the address is available. Lib is a combination of a bunch of obj.

2. Theoretically, you can connect to the OBJ file to reference other projects.(It can be considered that an OBJ file is equivalent to the CPP file generated by compilation. You can reference OBJ to replace CPP, or you can add CPP to replace obj.

), But in reality, Lib is usually used to implement mutual reference between projects.

3. the compiler will link some frequently-used libraries by default. You must specify other libraries by yourself.


Differences between lib and DLL

(1)Lib is required during compilation and DLL is required during runtime. If you need to complete source code compilation, it is enough to have Lib. If dynamic connection is also enabledProgramRun it. dll is enough.

. In the development and debugging stages, it is best to have both.

(2) common dynamic library programs include lib files and DLL files. The LIB file must be connected to the application during the compilation period, and the DLL file will be called only during the runtime. If there is a DLL file, the corresponding lib file is generally some index information, the specific implementation is in the DLL file.If only the Lib file is available, the Lib file is statically compiled and the indexes and implementations are all included.

The advantage of static compiling lib files is that dynamic libraries are no longer needed during installation. However, there are also some disadvantages, that is, the application is relatively large and the flexibility of the dynamic library is lost. During version upgrade, new applications must be released at the same time.

(3) In the case of a dynamic library, there are two files, one is the import library (. Lib) file (In fact, it is also a static library, but the function can only be linked to the EXE at the DLL entry during the link, instead of truly linking the function body to the EXE like the real static Link Library.

The dynamic link through lib actually uses static links for implementation.

). One is the DLL file. The imported file contains the name and location of the function exported by the DLL. The dll contains the actual function and data, the application uses the Lib file to link to the required DLL file. The functions and data in the library are not copied to the executable file. Therefore, in the executable file of the application, stores not the called function code, but the memory address of the function to be called in the DLL, in this way, when one or more applications are running, the program code is linked to the called function code, thus saving memory resources. From the above description, we can see that the DLL and. Lib files must be released along with the application, otherwise the application will produce errors.

There are two types of functions in the DLL:

(1) DLL export function, which can be called by a program;

(2) DLL internal functions can only be used in DLL programs, and applications cannot call them

Create static Link Library and dynamic link library

Create a [Win32 dynamic-Link Library] project in vc6 to create an empty DLL project.

Create a [Win32 static library] project in vc6 to create an empty lib Project (static Link Library project, only generate one lib file ).

There are two common methods to add lib files:

1. Put *. Lib in the lib directory of VC.

2. Modify the addtional library path in link-> input of Project setting and add your directory dll: binary code that can be actually run, with locating code!

3. You can also directly write the Lib file path in the object/library. (in this case, you can actually write any OBJ file or lib file ).

There is a personal method: when there is a time prompt for missing a identifier or something, you can use the file search tool (TC can directly search for binary files) to search for this identifier (General function name ), find out where it is put, and then reference it ,:-)

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.