Lockhead
Lockhead

Reputation: 2451

Building dependency trees

How do I build a dependency tree using C++? By dependency tree I mean, for example, checking what files a certain program needs in order to run. By checking that, I could find if there are any missing or corrupt files.

How do I do something like that?

edit:

I'm not looking for a program that does it for me!

Upvotes: 8

Views: 2459

Answers (2)

maverik
maverik

Reputation: 5606

Just a suggestion when talking about Windows: you can write a module that catches all the calls to open, read, write, ... a file from your application and builds the list of files requested possibly filtering such files as standard input/output, ports, devices, etc.

You can do this also on Linux (this is even easier than on Windows).

Anyway, I don't realize how you can build an hierarchy (tree). Just in case: you can use this solution in couple with another one (such as ldd, dep walker, etc).

Upvotes: 0

mgiuca
mgiuca

Reputation: 21377

There is no cross-platform method for calculating dependencies, because this is not actually a C++ problem. It is related to the executable format output by the compiler, and that is different on each platform.

On Linux (and probably other Unices), the ldd command is what you want. This prints out the (recursive) modules that will be required by the executable, and also tells you where they can currently be found on your system.

On Windows, Dependency Walker is an excellent graphical tool that lets you explore all of the DLLs that an executable (or another DLL) depends upon.

Upvotes: 2

Related Questions