#pragma comment的功能为什么是“该指令将一个注释记录放入一个对象文件或可执行文件中”?

六道佩恩 2019-01-13 11:25:24
注释记录?这是什么?所有地方都这一个解释,没有人说这个“注释记录”是什么东西,这句话该不会来自于机翻吧?
...全文
116 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2019-01-14
  • 打赏
  • 举报
回复
comment
#pragma comment( comment-type [, commentstring] )

Places a comment record into an object file or executable file. The comment-type is one of five predefined identifiers, described below, that specify the type of comment record. The optional commentstring is a string literal that provides additional information for some comment types. Because commentstring is a string literal, it obeys all the rules for string literals with respect to escape characters, embedded quotation marks ("), and concatenation.

compiler

Places the name and version number of the compiler in the object file. This comment record is ignored by the linker. If you supply a commentstring parameter for this record type, the compiler generates a warning.

exestr

Places commentstring in the object file. At link time, this string is placed in the executable file. The string is not loaded into memory when the executable file is loaded; however, it can be found with a program that finds printable strings in files. One use for this comment-record type is to embed a version number or similar information in an executable file.

lib

Places a library-search record in the object file. This comment type must be accompanied by a commentstring parameter containing the name (and possibly the path) of the library that you want the linker to search. Since the library name precedes the default library-search records in the object file, the linker searches for this library just as if you had named it on the command line. You can place multiple library-search records in the same source file; each record appears in the object file in the same order in which it is encountered in the source file.

linker

Places a linker option in the object file. You can use this comment-type to specify a linker option instead placing the option on the Link tab of the Project Settings dialog box. For example, you can specity the /include option to force the inclusion of a symbol:

#pragma comment(linker, "/include:__mySymbol")

user

Places a general comment in the object file. The commentstring parameter contains the text of the comment. This comment record is ignored by the linker.

The following pragma causes the linker to search for the EMAPI.LIB library while linking. The linker searches first in the current working directory and then in the path specified in the LIB environment variable.

#pragma comment( lib, "emapi" )

The following pragma causes the compiler to place the name and version number of the compiler in the object file:

#pragma comment( compiler )

Note For comments that take a commentstring parameter, you can use a macro in any place where you would use a string literal, provided that the macro expands to a string literal. You can also concatenate any combination of string literals and macros that expand to string literals. For example, the following statement is acceptable:

#pragma comment( user, "Compiled on " __DATE__ " at " __TIME__ )
棉猴 2019-01-14
  • 打赏
  • 举报
回复
#pragma是预处理指令,它的作用是设定编译器的状态或者指示编译器完成特定的动作。其格式为
#pragma Parameter
其中,Parameter表示参数,其值可以是message、once、resource以及comment等。当Paremeter是comment时,表示将一个注释记录放入到一个对象文件或可执行文件中。在项目中使用库文件时,就可以使用该指令。
#pragma comment指令的格式为
#pragma comment(comment-type, “commentstring”)
其中,comment-type是预定义的标识符,指定了注释的类型,其值可以是compiler、exestr、lib和linker;commentstring为comment-type提供附加信息的字符串。在项目中使用库文件时,需要将comment-type设置为lib,commentstring为库文件名。
#pragma comment(lib,"ws2_32.lib")

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧