6

I have an application, and a static library. The library appears to build just fine - it certainly compiles my foo and bar and geewhizz functions just fine, and creates the static library without any errors or warnings.

However, when the application builds and links to the static library, it manages to link to functions foo and bar but cannot find function geewhizz. How can I tell if geewhizz made it into the library? I can't see any /map option for libraries like there is for building the applications. And it is pointless using the \map option when building the application, because it can't find my geewhizz function, and has no basis to report on it.

I am working with a mixture of C and C++, and I suspect there is probably a function name mangling/translation issue, or calling convention issue, that is causing the problem, so I think having a list of the functions included in the library should be able to shine light on that. But if there is any more general advice for resolving such issues, I'd be pleased to hear it.

omatai
  • 3,448
  • 5
  • 47
  • 74
  • so you get a linking error, right? – Marco A. Jul 30 '14 at 22:41
  • @MarcoA.: Only when linking an executable against the shared library. He wants to know if his shared library is valid _before_ he tries to use it. – Mooing Duck Jul 30 '14 at 22:49
  • @MarcoA: Not any more - I have since fixed my link error by declaring `geewhizz` inside an `extern "C" {...}` construct. But I'm still interested to know how to get a listing of functions in a static library, because this would have helped confirm my suspicion a lot quicker. The static libary was always valid – omatai Jul 30 '14 at 22:49
  • 1
    You can try dumpbin.exe: http://stackoverflow.com/questions/375273/microsoft-equivalent-of-the-nm-command. I don't know whether it works on static libraries but I don't see why it wouldn't. – indiv Jul 30 '14 at 22:53
  • @indiv - great answer - it does work on static libraries - but really really really cryptic. nm command?!?!? You really have to be an insider to know what that is. – omatai Jul 30 '14 at 22:58
  • 1
    @WhozCraig - in light of the above, maybe you should mark that other answer as a duplicate of this one ;-) I think someone should spell out the `dumpbin /linkermember` syntax and gain a few free rep points as grateful people upvote both question and answer – omatai Jul 30 '14 at 23:00
  • `lib.exe` will likely also get at least some info, specifically the /list option. It will at least list the obis. – WhozCraig Jul 30 '14 at 23:00
  • @omatai: Glad it helped. If you'd like, you can be that someone and answer your own question. I won't leave an answer because I lack the environment to experiment for a quality answer. (I just knew that `nm` would do what you wanted on Linux and googled it) – indiv Jul 30 '14 at 23:12

1 Answers1

6

Thanks to helpful comments from @indiv and @WhozCraig in particular, you have at least these two options:

  • Use the /LIST option in Visual Studio's linker program (lib.exe)
  • Use the dumpbin utility with the /linkermember option

Visual studio is not exactly helpful in making the /LIST option easy to use. You will have to specify it as an additional option on the Command Line, but how to do that is not clear. /LIST on its own produces a listing to standard output, but neither specifying a file nor using the > redirection operator work in any obvious way. In fact, I've given up trying to work out how to make this option work at all.

Thankfully, dumpbin is a utility shipped with Visual Studio (even the Express versions) and is well documented here. So until someone makes /LIST remotely workable to ordinary people, use dumpbin.

omatai
  • 3,448
  • 5
  • 47
  • 74