화요일, 5월 13, 2008

TARGETLIBS와 SOURCELIBS

기존까지 "Building Powerfult Platform with Windows CE"에서 설명하는 데로 대충 이해하고 있었다.
그러다 최근 다시 생각해 볼 일이 있어 관련 내용을 찾아봤다.

Windows CE Help에는 다음과 같이 나와 있다.
TARGETLIBS
This macro definition specifies additional library (.lib) and object (.obj) files that should be linked into the target executable (.exe or .dll) file.

SOURCELIBS
This macro definition specifies library (.lib) files to be linked with the module specified in TARGETNAME.

This macro definition is typically only used when you are creating a new .lib file from other .lib files. Use TARGETLIBS macro when you are creating an executable (.exe or .dll) file.

마지막 부분은 SOURCELIBS가 나타내는 library들은 주로 새로운 TARGETNAME library를 만들기위해 사용되고, TARGETLIBS에 나열된 library들은 TARGETNAME executable을 만들기 위해 사용된다는 소리. (하지만 많은 경우 TARGETNAME executable을 만들기 위해서 sources file에서 TARGETLIBS와 SOURCELIBS가 같이 사용된다)

TARGETLIBS에서는 "linked into"라는 말이 사용되었고 SOURCELIBS에서는 "linked with"가 사용되었으니
TARGETLIBS는 target executable를 결과적으로 만들기 위해 link되어야 하는 것이고 SOURCELIBS는 build의 결과로 만들어진 TARGETNAME module과 link되는 것.
즉, TARGETLIBS + source -->TARGETNAME executable file
SOURCELIBS + TARGETNAME module --> ? (결과적으로 뭐가 된다는 것인지 나로서는 알수 없다)
이런 말인것 같다.
MICROSOFT website와 platform builder의 help에서 더이상의 자세한 정보는 찾아볼 수 없다.

Building Powerful Platforms with Windows CE에서는 다음과 같이 말한다.
page432
SOURCELIBS - platform dependent static libraries to be linked with source code
TARGETLIBS - libraries that must be linked with compiled source code
page288
The TARGETLIBS macro specifies object module libraries and import libraries (thoes used to reference the exported functions of a DLL).
The SOURCELIBS macro specifies modules that are linked not by unresolved symbols, but instead by the inclusion of all of the object modules contained in the LIB file in the final executable module.

이것은
SOURCELIBS는 source code와 link되는 것이고 TARGETLIBS는 compile된 source와 link되는 것.
Compiled source라는 말이 너무 모호하다. object file까지의 상태를 이야기하나 아니면 결과적인 module을 이야기 하나?
TARGETLIBS + compiled source code --> ?
SOURCELIBS + source code --> TARGETNAME module
TARGETLIBS는 static library, import library를 정의하고, SOURCELIBS는 static library를 정의한다는 말.
MS의 문서와는 완전히 다른 의미로 다가온다.

아래는 Wecom 게시물에서 찾은 것으로 google newgroup에서 퍼온거란다.
This is componentization feature of Windows CE.
The link has two steps.
First, whatever is in SOURCELIBS gets combined in a single library yourproductname_ALL.lib.
In the second step, executable module is linked from that library and all the targetlibs.

This is done to allow stubs to be conditionally linked:
If the function is defined into your source already, stubs get excluded.
If it is not there, stubbed version (returning ERROR_NOT_IMPLEMENTED or something to that effect) gets linked in instead.

If the link were to be performed in just one step, it would be impossible to predict which version (real or stub) would get included.
As it is, implemented functions have a priority over stubs.

(출처 : http://www.iwecom.co.kr/ce/advanced_read.asp?id=20906&vgoto=1&SearchString=Y&category=WF_wince)
이 글을 읽어보면 왜 SOURCELIBS가 static library를 나타내는지 알수 있다.
종합해 보자면, source code는 compile된 후 우선 SOURCELIBS의 static library와 link되어 target module이 되고, 이게 나중에 필요한 경우 다시 TARGETLIBS의 import library와 link된다는 말.
결과물이 TARGETNAME module이 SOURCELIBS와 우선 static하게 link되어 user defined function을 call하게 하는데, 만일 이게 없다 하더라도 나중에 dynamic하게 TARGETLIBS와 link되게 하여 stub function이나 stardard function이 call될 수 있게 하겠다는 것.


Google에서 발췌한 글을 읽자면 "Building Powerful Platform with Windows CE"의 내용이 틀린말은 아니라는 생각을 하게 된다. BPPW에서는 TARGETLIBS가 static libray도 나타낸다고 하는데 이부분은 확인 못했다.