Friday, 12 December 2008

Windows CE: TARGETLIBS vs. SOURCELIBS

Hi everybody,

Did you ever wonder why there is both TARGETLIBS and SOURCELIBS macros in the Windows CE SOURCES file? Well I did and here is the explanation why:

First of all the reason to have these macros is that we can componentizise our module but why not just have one of these macros? The difference is in which one will be listed first to the linker:

  • When building an .exe, TARGETLIBS will be listed first to the linker
  • When building a .dll, SOURCELIBS will be listed first to the linker
  • When building a .lib, only SOURCESLIBS will be listed to the linker
In any case the linker will always use the first version of particular function that it finds.

Have fun!

1 comment:

Embedded Shack said...

Hi Jochen,

In your post, you mentioned "When building a .dll, SOURCELIBS will be listed first to the linker...In any case the linker will always use the first version of particular function that it finds.". From what i have googled, this is also het way to "override" stubs (i.e. a function in SOURCELIBS will be favoured and the same function in TARGETLIBS will be disregarded.
However, if that was indeed true then if I had a driver(dll) with the following sources file:
TARGETLIBS=\
$(_SYSGENSDKROOT)\lib\$(_CPUINDPATH)\coredll.lib \
$(_SYSGENSDKROOT)\lib\$(_CPUINDPATH)\ceosutil.lib \
$(_SYSGENOAKROOT) \


SOURCELIBS=\
$(_PLATCOMMONLIB)\$(_CPUINDPATH)\mydriver.lib

which compiles successfully, the why would it fail (unresolved symbols) when i modify the sources file as follows:

TARGETLIBS=\
$(_SYSGENSDKROOT)\lib\$(_CPUINDPATH)\coredll.lib \
$(_SYSGENSDKROOT)\lib\$(_CPUINDPATH)\ceosutil.lib \
$(_SYSGENOAKROOT)\lib\$(_CPUINDPATH)\ceddk.lib \
$(_SYSGENSDKROOT)\lib\$(_CPUINDPATH)\mmtimer.lib \
$(_PLATCOMMONLIB)\$(_CPUINDPATH)\pmicSdk_mc13892_$(_COMMONSOCDIR).lib

SOURCELIBS=\

Shouldn't the compiler simply use the functions in TARGETLIBS?

Thanks,
John