Use of Pragma comment

Source: Internet
Author: User
This macro places a comment to the object file or executable file.
 
# Pragma comment ( Comment-type[,"Commentstring"])

Comment-typeIs a predefined identifier. It specifies the annotation type and should beCompiler,Exestr, Lib, linker.
Commentstring isComment-typeA string that provides additional information,
Remarks:
1. Compiler: place the version or name of the compiler to an object file. This option is ignored by linker.
2. exestr: It will be canceled in a later version.
3. Lib: place a library search record to the object file. This type should be consistentCommentstring (specify the name and path of the Lib you want to search for by liner)
The name of this library is placed behind the default library search record of the object file. linker searches for this library just like you enter this command on the command line. You can
Set multiple database records in a source file. The order of these records in the object file is the same as that in the source file. If the order of the default and additional libraries is required
The difference is that the use of the Z compiler switch prevents default libraries from being placed in the object module.
4. linker: specify a connection option so that you do not need to enter the connection in the command line or in the development environment.
Only the following Linker options can be passed to linker.
 
(1)/defaultlib:Library

/Defaultlib OptionLibraryAdd to the list of libraries that link searches for when parsing references. Use the library specified by/defaultlib to search for the specified library on the command line and the default library specified in the. OBJ file.

Ignore all default libraries (/nodefalib Lib) option to override/defaultlib: Library. If the same library name is specified in both,Ignore Database(/Nodefaultlib:Library) Option will override/defalib Lib:Library.

(2)/export:Entryname[,@Ordinal[, Noname] [, Data]

With this option, you canProgramExport the function so that other programs can call it. You can also export data. It is usually defined and exported in DLL.EntrynameIs the name of the function or data item to be used by the calling program.OrdinalSpecify an index with a range of 1 to 65,535 in the export table. If no index is specifiedOrdinal, One link is allocated.NonameThe keyword exports the function as the serial number only. NoEntryname.

DataKeyword specifies that the export item is a data item. Data items in the customer program must be usedExtern _ declspec (dllimport).
There are three methods for exporting definitions, which are recommended in sequence:

    1. Source codeIn

    2. Exports statement in the. Def File

    3. /Export specification in link command

All three methods can be used in the same program. Link also creates Import and Export files when generating programs that contain export, unless the. Exp file is used in the generation.
Link uses the identifier modifier. The identifier is modified by the compiler when the. OBJ file is created. IfEntrynameIt is specified to the linker in its unmodified form (instead of in the sourceCode), Link tries to match the name. If a unique match name cannot be found, link sends an error message. When you need to specify an identifier to the linker, use dumpbin to obtain the modifier form of the identifier.

 
(3)/include:Symbol

The/include option notifies the linker to add the specified symbol to the symbol table.

To specify multiple symbols, enter a comma (,), semicolon (;), or space between symbol names. Specify/include for each symbol on the command line:Symbol.
The linker adds objects containing symbolic definitions to the program for parsing.Symbol. This function is useful for adding library objects that do not link to the program. You can use this option to specify the symbol to remove it from/OPT: ref.

 


We often use the # pragma comment (Lib, "*. lib") class.
# Pragma comment (Lib, "ws2_32.lib") indicates link to the library ws2_32.lib.
This method is the same as writing ws2_32.lib to the Project Settings.
When someone else uses your code, there is no need to set the project settings.

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.