views:

161

answers:

3

I have an inherited project that uses a build script (not make) to build and link the project with various libraries.

When it performs a build I would like to parse the build output to determine what and where the actual static libraries being linked into the final executable are and where are they coming from.

The script is compiling and linking with GNU tools.

A: 

Static libraries, that makes life more difficult in this regard. In case of dynamic libraries you could just have used ldd on the resulting executable and be done with it. The best bet would be some kind of configuration file. Alternatively you could try to look for -l arguments to gcc/ld. Those are used to specify libraries. You could write a script for extracting it from the output, though I suspect that you will have to do it manually because by the time you know what the script should look for you probably already know the answer.

Leon Timmermans
A: 

It is probably possible to do something useful using e.g. Perl, but you would have to provide more details. On the other hand, it could be easier to simply analyze the script...

Xavier Nodet
+1  A: 

You might try using the nm tool. Given the right options, it will look at a binary (archive or linked image) and tell you what objects were linked into it.

Actually, here's a one-liner I use at work:

#!/bin/sh

nm -Ag $* | sed 's/^.*\/\(.*\.a\):/\1/' | sort -k 3 | grep -v ' U '

to find the culprits for undefined symbols. Just chop off the last grep expression and it should pretty much give you what you want.

Ben Collins