Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find which functions are in a static c/c++ library in Visual Studio

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.

like image 324
omatai Avatar asked Jul 30 '14 22:07

omatai


People also ask

How do I view the contents of a .LIB file?

Like it can be seen in other answers you'll have to open a Developer Command Prompt offered in your version of Visual Studio to have dumpbin.exe in your execution path. Otherwise, you can set the necessary environment variables by hand. dumpbin /EXPORTS yourlibrary. lib will usually show just a tiny list of symbols.

What is static library in Visual Studio?

The sample projects in this article were created using Visual Studio 2010. A static library consists of object files that are linked together with an exe file. Object files are the output of compilers of unmanaged code and consists of functions that can only be used by unmanaged code.


1 Answers

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.

like image 55
omatai Avatar answered Sep 22 '22 03:09

omatai