#pragma comment 官方文档翻译

一 格式

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

作用

Places a comment record into an object file or executable file.

翻译:将一个注释记录放入一个object文件或者可执行文件中。

参数:

comment-type

有5种预定义的标识:compiler、exestr、lib、linker、user

二  comment-type

1 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.

翻译:将编译器的名称和版本号放入object 文件,该注释记录会被链接器忽略,如果你提供了commentstring 参数,编译器会生成一个警告。

举例:

#pragma comment( compiler )

2 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.

exestr is deprecated and will be removed in a future release; the linker does not process the comment record.

翻译:将commentstring 放入object 文件中,在链接时该字符串被放入可执行文件中。当加载可执行文件时,该字符串不会被加载入内存中。但是它可以被能在文件找到可打印的字段串之类的程序查找出来。该标识的一个应用是将版本号或者类似信息嵌入到可执行文件中。

exestr在将来的发布版本中会被移除,链接器不会处理该注释记录。

3 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. The library name follows 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 provided that the library is not specified with  /nodefaultlib. 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.

If the order of the default library and an added library is important, compiling with the switch  /Zl will prevent the default library name from being placed in the object module. A second comment pragma then can be used to insert the name of the default library after the added library. The libraries listed with these pragmas will appear in the object module in the same order they are found in the source code.

翻译:将一个库搜索记录放入object 文件。该标识类型必须包括commentstring 参数,该参数包含链接器要搜索库的库名称或者路径。该库名称紧跟在object 文件的默认库搜索记录后面,如果你在命令行中已命名该库并且没有指定 /nodefaultlib,链接器会搜索该库。你可以在同一个源文件中放入多个库搜索记录,每个记录在对象文件中出现的顺序与源文件中一致。

如果默认库和增加的库的顺序很重要,可以使用编译开关 /Zl可以阻止默认库放入object 模块中,再次使用comment可以将默认库名称加到增加的库的后面,在object模块中的库顺序与源代码中一致。

举例:

#pragma comment( lib, "emapi" )

4 linker

Places a linker option in the object file. You can use this comment-type to specify a linker option instead of passing it to the command line or specifying it in the development environment. For example, you can specify the /include option to force the inclusion of a symbol:

 Only the following (comment-type) linker options are available to be passed to the linker identifier: 

•/DEFAULTLIB 
•/EXPORT 
•/INCLUDE 
•/MANIFESTDEPENDENCY 
•/MERGE 
•/SECTION 

翻译:将一个链接选项放入object文件。可以通过该标识指定一个链接选项替代在命令行或者开发环境中设置。例如你可以指定/include选项来强制包含某个符号。

全部linker option:https://docs.microsoft.com/en-us/cpp/build/reference/linker-options?view=vs-2017

举例

#pragma comment(linker, "/SUBSYSTEM:CONSOLE")  // 显示cmd窗口

5 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.

翻译:将一个通用注释放入object文件。参数commentstring包含该注释文本,该注释记录会被链接器忽略

举例:

#pragma comment( user, "Compiled on " __DATE__ " at " __TIME__ )

三 原文

官方文档:https://docs.microsoft.com/en-us/cpp/preprocessor/comment-c-cpp?view=vs-2017

猜你喜欢

转载自blog.csdn.net/luoshabugui/article/details/82858135
今日推荐