VS Medium def files for generating DLLs and Lib files

Source: Internet
Author: User

VS2005 uses DEF file to generate DLL and LIB

VS2005 use def file to generate DLL and LIB, and VC6 settings are not the same, VC6 engineering, as long as there is a DEF file and add it to the project, VC6 can automatically generate the DLL and its corresponding LIB file.

But VS2005 is different, you need to specify a DEF file, the following methods:
For example:

Add the Sqlite3.def to the project.

Select the linker in the Engineering > properties, and then locate the entry. Enter SQLITE3.DEF in the module definition file

Note: You need to enter this entry in both Debug and release.

Comparison of __declspec (dllexport) and *.def files
Article Source: DIY Tribe (http://www.diybl.com/course/3_program/c++/cppxl/2008105/147591.html)

First, __declspec (dllexport)
In a 32-bit compiler version, you can use the __declspec (dllexport) keyword to export data, functions, classes, or class member functions from a DLL. __declspec (dllexport) adds an export directive to the obj file at link time, so you do not need to use a. def file. Of course, the *.def file can still be used with __declspec (dllexport), because different compilers can define the. def file by ordinal call for different name mangling rules for the member functions of the class. It's complicated to write def for each DLL, and currently there are fewer def uses, and more is using __declspec (dllexport) to define the output functions of the DLL in the source code.

To output all members of a class: data or functions, __declspec (dllexport) is declared to the left of the class name:
Class __declspec (dllexport) class1{}
If a class has no data members, __declspec (dllexport) is ignored by the compiler when it is placed before the class keyword, and there is no LIB build, as follows:
__declspec (dllexport) class class1{}


Advantages and disadvantages of using __declspec (dllexport) (ZZ)
Using __declspec (dllexport) is convenient because you do not have to consider maintaining the. def file and getting the decorated name of the exported function. This method is useful, for example, if you design a DLL for use by your own controlled application. If you rebuild the DLL with the new export function, you must also rebuild the application, because if you recompile with a different version of the compiler, the decorated name of the exported C + + function may change.

Two, def file
In fact, the function of DEF file is equivalent to extern "C" __declspec (dllexport)

The role of privtate in def files

The Optional keyword PRIVATE prevents EntryName from being placed to the import library generated by LINK. It has no
Effect on the "export in" image also generated by LINK. Using private, the generated Lib has no corresponding method or data entryname so it cannot be called implicitly by the client.

Use. DEF File Pros and cons (ZZ)
Exporting a function in a. def file allows you to control the export ordinal. When additional exported functions are added to the DLL, they can be assigned a higher ordinal value (higher than any other exported function). When you do this, an application that uses implicit linking does not have to be relink with the new import library that contains the new function. This is important, for example, when designing a third-party DLL that will be used by many applications. You can continuously enhance DLLs by adding additional functionality while ensuring that existing applications continue to use the new DLLs normally. MFC DLLs are generated by using a. def file.

Another advantage of using a. def file is that you can use the NONAME property to export a function that simply places an ordinal in the DLL's export table. For DLLs with a large number of exported functions, the Noname property can be used to reduce the size of the DLL file. For information about writing module definition statements, see the Rules for module definition statements. For more information about ordinal exports, see exporting functions from a DLL by ordinal rather than by name.

The main disadvantage of using a. def file is that when you export a function in a C + + file, you must place the decorated name in the. def file, or you can use the external "C" to define the exported function with the standard C link to avoid the compiler's name modification. If you need to place the decorated name in a. def file, you can get the decorated name by using the DUMPBIN tool or the/MAP linker option. Note that the compiler-generated decorated name is compiler-specific. If you place the decorated name produced by the Visual C + + compiler in a. def file, the application that is linked to the DLL must also be generated in the same version of Visual C + +, so that the decorated name in the calling application can match the exported name in the DLL's. def file.
Article Source: DIY Tribe (http://www.diybl.com/course/3_program/c++/cppxl/2008105/147591.html)

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.