[C + +] pragma comment used

2011-01-10  来源:本站原创  分类:CPP  人气:101 

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:

  1. Source code __declspec (dllexport)
  2. . Def files in the EXPORTS statement
  3. 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.

(3)/INCLUDE:symbol

/ 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
相关文章
  • [C + +] pragma comment used 2011-01-10

    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,

  • pragma comment(linker,"/SECTION:shared,RWS") 2012-06-26

    pragma comment(linker,"/SECTION:shared,RWS") Windows在一个Win32程序的地址空间周围筑了一道墙.通常,一个程序的地址空间中的数据是私有的,对别的程序而言是不可见的.但是执行多个执行实体表示了程序的所有执行实体之间共享数据是毫无问题的.当您在一个窗口中增加或者删除一个字符串时,这种改变将立即反映在其它的窗口中. 在全部例程之间,STRLIB共享两个变量:一个字符数组和一个整数(记录已储存的有效字符串的个数).这两个变量储存在共享的一个

  • #pragma comment 使用 2013-03-06

    在编写程序的时候,我们常用到#pragma指令来设定编译器的状态或者是指示编译器完成一些特定的动作. #pragma once : 这是一个比较常用的指令,只要在头文件的最开始加入这条指令就能够保证头文件被编译一次,避免文件被重复包含. #pragma comment : 该 指令的格式: #pragma comment( comment-type [,"commentstring"] ) 该指令将一个注释记录放入一个对象文件或可执行文件中. comment-type(注释类型):可以

  • # Ifdef and # pragma once 2010-06-03

    In the wizard generated using VC6.0 header file can often see the following code: # If! Defined (AFX_RESIZABLELAYOUT_H__INCLUDED_) # Define AFX_RESIZABLELAYOUT_H__INCLUDED_ # If _MSC_VER> 1000 # Pragma once # Endif / / _MSC_VER> 1000 ... # Endif / /

  • dll # pragma data_seg data sharing 2010-10-18

    # Pragma data_seg ("flag_data") int count = 0; # Pragma data_seg () # Pragma comment (linker, "/ SECTION: flag_data, RWS") This method can only be used when there is no def file, if the exported file by def, then set the necessary sett

  • WSAEventSelect simple model (note the comment areas) 2010-10-29

    // Win32SocketTest.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "winsock2.h" //#pragma comment(lib,"wsock32.lib") #pragma comment(lib,"Ws2_32.lib") #include <iostream

  • pragma 预处理指令详解 2010-12-23

    pragma指令简介 在编写程序的时候,我们经常要用到#pragma指令来设定编译器的状态或者是指示编译器完成一些特定的动作. 下面介绍了一下该指令的一些常用参数,希望对大家有所帮助! 一. message 参数. message 它能够在编译信息输出窗 口中输出相应的信息,这对于源代码信息的控制是非常重要的.其使用方法为: #pragma message("消息文本") 当编译器遇到这条指令时就在编译输出窗口中将消息文本打印出来. 当我们在程序中定义了许多宏来控制源代码版本的时候,我

  • #Pragma 用法总结 2012-06-12

    百科名片 http://baike.baidu.com/view/1451188.htm 在所有的预处理指令中,#Pragma 指令可能是最复杂的了,它的作用是设定编译器的状态或者是指示编译器完成一些特定的动作.#pragma指令对每个编译器给出了一个方法,在保持与C和C++语言完全兼容的情况下,给出主机或操作系统专有的特征.依据定义,编译指示是机器或操作系统专有的,且对于每个编译器都是不同的. 1.message 参数 Message 参数能够在编译信息输出窗口中输出相应的信息,这对于 源代码

  • #pragma 用法 2012-07-10

    今天刚开始调试windows核心编程中的例程就感觉十分难懂,原因是自己的c++基本功力实在太弱了 首先在windows编程的过程中大量的使用宏的问题. #pragma 的用法 在所有的预处理指令中,#Pragma 指令可能是最复杂的了,它的作用是设定编译器的状态或者是指示编译器完成一些特定的动作.#pragma指令对每个编译器给出了一个方法,在保持与C和C ++语言完全兼容的情况下,给出主机或操作系统专有的特征.依据定义,编译指示是机器 或操作系统专有的,且对于每个编译器都是不同的. 其格式一般

  • C语言#pragma预处理 2012-11-17

    在所有的预处理指令中,#pragma 指令可能是最复杂的了,它的作用是设定编译器的状态或者是指示编译器完成一些特定的动作.#pragma 指令对每个编译器给出了一个方法,在保持与C 和C ++语言完全兼容的情况下,给出主机或操作系统专有的特征.依据定义,编译指示是机器或操作系统专有的,且对于每个编译器都是不同的. 其格式一般为: #pragma para 其中para 为参数,下面来看一些常用的参数. 一.#pragma message message 参数:Message 参数是我最喜欢的一个

  • [转]预编译指令#pragma的用法 2012-11-28

    [转]预编译指令#pragma的用法 在所有的预处理指令中,#Pragma 指令可能是最复杂的了,它的作用是设定 编译器 的状态或者是指示编译器完成一些特定的动作.#pragma指令对每个编译器给出了一个方法,在保持与C和C++语言完全兼容的情况下,给出主机或 操作系统 专有的特征.依据定义,编译指示是机器或操作系统专有的,且对于每个编译器都是不同的. 其格式一般为: #pragma Para.其中Para 为参数,下面来看一些常用的参数 1.message 参数 Message 参数能够在编译

  • #pragma用法详解 2014-07-29

    Author :Jeffrey My Blog:http://blog.csdn.net/gueter/ 目录: (0) 前言 (1) #pragma message能够在编译信息输出窗口中输出相应的信息 (2) #pragma code_seg能够设置程序中函数代码存放的代码段,开发驱动程序的时会用到 (3) #pragma once若用在头文件的最开始处就能够保证头文件被编译一次 (4) #pragma hdrstop表示预编译头文件到此为止 (5) #pragma resource "*.

  • java calling c (c + +) to write the dll files and steps for implementation (transfer) 2010-03-29

    JNI using the skills bit by bit in this 32-bit Windows platform, Java native methods to achieve provides a useful example of the steps and guidelines. The examples in this article was created using Sun Microsystems's Java Development Kit (JDK) versio

  • DLL shared data segment, the process of data sharing for multi Summary 2010-02-02

    DLL shared data segment, the process of data sharing for multi Summary Some time ago has been realized with the WM_COPYDATA message the process of data communication, the software upgrades would like to learn about, DLL shared application data segmen

  • Of UDP through NAT P2P Theory and Implementation 2010-03-09

    Forum on the P2P principle often discussed, but return to discuss the discussion, there is little for something real (source code). Oh, here I own a source code implementation to illustrate the principle of UDP through NAT. First of all, will introdu

  • gcc compiled dll and call the dll (change) 2010-03-13

    Original: http://blog.csdn.net/denglei265/archive/2009/02/14/3889470.aspx Method 1: There are three documents: print.h, print.c, test.c ************************************************** ************* print.h: file contents # Ifndef PRINT_H # Define

  • vc socket programming 2010-03-16

    1.TCP server side: #include <Winsock2.h> #include <stdio.h> #pragma comment(lib,"WS2_32.lib") void main() { WORD wVersionRequested; WSADATA wsaData; int err; wVersionRequested = MAKEWORD( 1, 1 ); err = WSAStartup( wVersionRequested,

  • MoveFileEx achieved using a hidden program. Self-starting and self-delete 2010-03-17

    MoveFileEx achieved using a hidden program, self-starting and self-delete First, understand MoveFileEx MoveFileEx is MoveFile function extension function is used to move files, but added some features. MoveFileEx function prototype is as follows: BOO

  • ArcSDE C API to read data 2010-03-17

    #include "stdafx.h" #include "windows.h" #include "sdetype.h" #include "sdeerno.h" #include "assert.h" #include <iostream> #pragma comment(lib, "sde.lib") using namespace std; SE_LAYERINFO

  • VS static library preparation 2010-03-11

    Visual Studio prepared under the static library Use VS to establish the console - Static library (static library) project libTest.h header files #ifndef GUARD_LIBTEST_H #define GUARD_LIBTEST_H #ifdef __cplusplus extern "C" { #endif int myadd(int