This article comes from: http://www.cppblog.com/xczhang/archive/2008/01/10/40866.html
Place a comment in the macro to the object file or executable file.
#pragma comment( comment-type [,"commentstring"] ) comment-type Is a predefined identifier, specify the type of comment , Should be compiler,exestr,lib,linker One . commentstring Is a provision for the comment-type A string that provides additional information , Remarks: 1.compiler: Version of the compiler or place name to an object file, this option is linker Ignored . 2.exestr: In a future version will be removed . 3.lib: Place a library search records to the object file, and this type should be commentstring( Specify your search to Liner lib The name and path ) Object name of the library files on the default library search history behind ,linker Search this, this library just as you enter this command as the command line. You can Set in a source file multiple database records, they object File in the order and in the same order as the source file. If the default order of libraries and additional libraries need to Differences, the use of Z Compiler switch is to prevent the default library modules into the object . 4.linker: Specify a connection option, so do not enter on the command line or in a development environment set up . Only the following linker options can be passed to Linker.
- / DEFAULTLIB
- / EXPORT
- / INCLUDE
- / MANIFESTDEPENDENCY
- / MERGE
- / SECTION
(1)/DEFAULTLIB:library /DEFAULTLIB Option of a library LINK referenced in the resolution added to the library list when the search . With /DEFAULTLIB Library specified on the command line and after the specified library. Obj file to be specified before the default library search .
Ignore all default libraries (/ NODEFAULTLIB) option to override / DEFAULTLIB: library. If specified in both the same library name, ignore library (/ NODEFAULTLIB: library) option overrides / DEFAULTLIB: library.
(2) / EXPORT: entryname [, @ ordinal [, NONAME]] [, DATA]
With this option, you can export functions from the program so that other programs can call the function. You can also export the data. Usually defined in the DLL export. entryname is the calling program to use the function or data item name. ordinal in the export table in the specified range of the index from 1 to 65,535; If you do not specify ordinal, the LINK will be assigned one. NONAME keyword function to export the serial numbers only, no entryname.
DATA key export item for the specified data item. Data item in the client must be extern __declspec (dllimport) to declare.
There are three ways to export the definition, in accordance with the recommended order of use:
- Source code __declspec (dllexport)
- . Def files in the EXPORTS statement
- LINK command / EXPORT specification
All three methods can be used in the same program. LINK exported in the generated program contains also creates an import library, unless used in generation. Exp file.
LINK uses the modified form of the identifier. Compiler to create. Obj file modification identifier. If entryname specified in its unmodified form to the linker (as in the source code with), the LINK will attempt to match the name. If you can not find the name of a unique match, LINK issues an error message. When you need the identifier assigned to the linker, use Dumpbin tool for the modification of the identifier name forms.
/ INCLUDE option tells the linker to specify the symbol to the symbol table.
To specify more than one symbol, type in the symbol names with a comma (,), semicolon (;) or spaces. At the command line, specify the time for each symbol / INCLUDE: symbol.
Linker defined by the object will contain the symbol added to the program to resolve the symbol. This feature does not link to add to the program contains a library object is very useful. This option specifies the symbol used by / OPT: REF rewritten to remove the symbol.
We often use the #pragma comment(lib,"*.lib") Such . #pragma comment(lib,"Ws2_32.lib") That the library link Ws2_32.lib . And write in the project settings in the same effect as links Ws2_32.lib , However, this method to write Others in the use of program code, when you no longer need to set the project settings