'pragma'에 해당되는 글 1건

  1. 2007.04.29 #pragma comment(lib, "something.lib")
프로그래밍/C/C++2007.04.29 01:00

ex) #pragma comment(lib, "something.lib")

 

#pragma는 전처리기(precompiler)다.

#define 처럼 컴파일할 때 처리를 하게 된다.

 

위의 예와 같이 하게되면

project setting 에서 c/c++ 탭쪽에 project options 에 lib들을 지정할 수 있는데

이와 동일한 기능을 소스에 넣을 수 있다.

 

 

다음과 같은 형식을 같는다.

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

 

comment-type은 따옴표 필요없이 넣는 것이고,

commentstring은 따옴표 안에 문자열을 넣어야 한다.

 

comment-type에는 compiler, exestr, lib, linker, user 등을 넣을 수 있다.

 

일단은 lib만 알고 넘어가고, 자세한 것은 msdn에서 필요할 때 찾기로 한다.

-----------------------------------------------------------------------------------

C/C++ Preprocessor Reference 
comment (C/C++) 

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

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

The comment-type is one of the predefined identifiers, described below, that specifies 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.

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

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 /Zl switch 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.

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:

코드 복사
#pragma comment(linker, "/include:__mySymbol")

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

  • /DEFAULTLIB

  • /EXPORT

  • /INCLUDE

  • /MANIFESTDEPENDENCY

  • /MERGE

  • /SECTION

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 )
NoteNote

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__ ) 
-----------------------------------------------------------------------------------

 

 

#

이러한 작은 지식이라도 모두 다 적어놓기로 했다..

Posted by 시난