[Use of C/c++]pragma comment

Source: Internet
Author: User

The macro places a comment into the object file or executable file.

   #pragma comment ( comment-type [,"  commentstring  "] ) 

comment-type is a predefined identifier that specifies the type of comment, which should be compiler, exestr,lib, One of the linker .
commentstring is a string that provides additional information for Comment-type ,
Remarks:
1, Compiler: Place the compiler's version or name into an object file, which is ignored by linker.
2, Exestr: will be canceled in a later version.
3, Lib: Place a library search record into the object file, this type should be and commentstring (Specify the name and path of the lib you want to search for liner)
The name of the library is placed behind the default library search record for the object file, and linker searches for this library just as you would enter this command at the command line. You can
set up multiple library records in one source file, in the same order in the object file as in the source file. If the order of the default and attached libraries is
different, using the z-compile switch is to prevent the default library from being placed in the object module.
4, Linker: Specifies a connection option so that it does not have to be entered at the command line or set in the development environment.
only the following linker option can be passed to linker.
      • /defaultlib
      • /export
      • /include
      • /manifestdependency
      • /merge
      • /section
(1)/defaultlib:Library

The library is added to the list of libraries that LINK searches when parsing references. The library specified by/defaultlib is searched after the library specified on the command line and the default library specified in the. obj file.

Override/defaultlib:library for all default library (/NODEFAULTLIB) options. If you specify the same library name in both, the Ignore libraries (/NODEFAULTLIB:Library) option overrides the/defaultlib:Library.

(2)/export:entryname[, @ordinal[, Noname]][,data]

With this option, you can export a function from a program so that other programs can call the function. You can also export data. Exports are typically defined in a DLL. EntryName is the name of the function or data item to be used by the calling program. ordinal specifies an index of 1 to 65,535 in the export table, and if no ordinal is specified , LINK assigns one. The NONAME keyword only exports the function as an ordinal, without entryname.

The Data keyword specifies that the export item is an item. Data items in the client program must be declared with extern __declspec (dllimport) .
There are three ways to export definitions, followed by the recommended order of use:

      1. __declspec (dllexport) in source code
      2. Exports statements in. def files
      3. The/EXPORT specification in the LINK command

All three of these methods can be used in the same program. LINK also creates an import library when the program that contains the export is generated, unless the. exp file is used in the build.
LINK uses the decorated form of an identifier. The compiler modifies the identifier when creating the. obj file. If entryname is assigned to the linker in its unmodified form (as in the source code), link attempts to match the name. If a unique matching name cannot be found, LINK issues an error message. When you need to assign an identifier to the linker, use the Dumpbin tool to get the decorated name 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, type a comma (,), semicolon (;)) between the symbol names. or spaces. On the command line, specify one/include: symbol for each symbol.
The linker parses the symbol by adding the object that contains the symbol definition to the program . This feature is useful for adding library objects that are not linked to a program. Use this option to specify that the symbol will override the removal of the symbol through/OPT:REF.

We often use this kind of #pragma comment (lib, "*.lib").
#pragma comment (lib, "ws2_32.lib") means that the link ws2_32.lib this library.
As in the project setup, the same effect as the ws2_32.lib, but this method writes
Program others use your code when you don't have to set up the project settings

Related information:
Http://www.cppblog.com/xczhang/archive/2008/01/10/40866.html

[Use of C/c++]pragma comment

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.