user1354557
user1354557

Reputation: 2503

Statically linking multiple libraries with WinDDK

I am using the DDK to build a project. Several of the build targets generate small internal libraries -- for simplicity, let's call them LibA.lib, LibB.lib, and LibC.lib. But the code for LibA references code from LibB and LibC. To use LibA in a project, you also need to include LibB.lib, and LibC.lib to resolve all of the dependencies. What I want to do is link LibB and LibC into LibA such that a user only needs to include LibA.lib. How can I accomplish this?

The SOURCES file for LibA looks something like this:

TARGETNAME=LibA
TARGETTYPE=LIBRARY

TARGETPATH=..\lib\$(DDKBUILDENV)

INCLUDES = .; \
           ..\LibB; \
           ..\LibC; \
           $(CRT_INC_PATH) \
           $(SDK_INC_PATH)

SOURCES = LibA_main.cpp \
          LibA_file2.cpp \
          LibA_file3.cpp

I understand that you can manually link libraries with link.exe; e.g.,

link.exe /lib LibA.lib LibB.lib LibC.lib

But if possible, I would like some way to achieve this same effect as a part of the build process for LibA, because some targets at a later point of the build process rely on LibA.

Thanks!

Upvotes: 0

Views: 659

Answers (3)

0xC0000022L
0xC0000022L

Reputation: 21319

I realize this is a late answer and it may not even be what you want in the end. However, ddkbuild.cmd has a pretty nifty mechanism to run actions before and after a build inside a particular directory.

We use this in one of our driver libraries which necessarily gets built as a number of static libraries and as a final step linked into one big static library much like you want. If you are able to use something like ddkbuild.cmd in your project, this would provide a solution and it's a solution that would work in automated builds, too.

NB: as far as I'm aware you cannot achieve what you want directly with build.exe. However, it's well possible that with some make (NMake) file acrobatics you could achieve a similar result. So the question is whether it's worth reinventing the wheel when there is one already.

Upvotes: 1

user1672329
user1672329

Reputation: 26

I have encountered the same situation as you. Google a lot of and still have no solution. Fortunately, I found a way to resolve it finally. You can try it, add the below statement in your libA sources file.

LIBRARIAN_FLAGS = $(LIBRARIAN_FLAGS) libB.lib libC.lib

Upvotes: 0

Carey Gregory
Carey Gregory

Reputation: 6846

The lib utility can combine libraries. Using your example, the command would be:

lib /out:CombinedLib.lib LibA.lib LibB.lib LibC.lib

Upvotes: 0

Related Questions