1. 程式人生 > >#pragma comment 官方文件翻譯

#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