How to list the imports of a static library

Started by
7 comments, last by Bregma 14 years, 1 month ago
Hi, Could you anyone please help me with the way to list the imports of a static library. I have used dumpbin /IMPORTS to list the imports a dll but I have not able to find a way to do the same on a static library. Thank you in advance, Rohini Chandra
Advertisement
Static libraries do not have imports. Think of them kind of like a .zip file of .objs.
Hi Codeka,

Thank you for the reply. I actually want to list the WinAPI's used by the static library. I was able to do that for a dll using dumpbin. Do you know if there is any other way to get that information?

Thanks & Regards,
Rohini Chandra.
Quote:Original post by rohini chandra
Thank you for the reply. I actually want to list the WinAPI's used by the static library.


The object files inside a static library don't know where the function implementations are going to come from at link time, so strictly speaking that question doesn't make sense.

The best you could hope to do is try to parse the lib/object format, pull out all the function names and compare against a list of known Windows API functions. That doesn't smell right to me, though.

Why do you want to do this? There might be a better way.
The only way i can think of to do this is to compile a file with only a DllMain entry point and nothing else to an .obj. Embed this obj into your program, and then invoke LINK.EXE from inside your program, linking against the obj to produce a DLL. Then walk the imports of the DLL and see which ones come from standard windows DLLs (kernel32.dll, user32.dll, etc). Make sure to use the linker option to remove unrefernced symbols.
Hi,

Thanks to both of you. I am trying to build the static library as a dll as
cache_hit suggested.

Reg the_edd's question:Why do you want to do this? There might be a better way.

I need to port the static library in question from windows to Linux. So I am
trying to know the WinAPI's used in the code to estimate the effort of porting.

Thanks & Regards,
Rohini Chandra
You could just do a dumpbin of the Windows DLLs (USER32.dll, KERNEL32.dll, etc) then do a string-search in the .lib file for those strings. It won't be perfect, but it should be pretty close.

Though I don't see how you can port a static lib to Linux without the actual source code. How was the static lib compiled in the first place? No Linux compiler that I'm aware of is able to read MSVC's .lib file format...
Quote:Original post by rohini chandra
Reg the_edd's question:Why do you want to do this? There might be a better way.

I need to port the static library in question from windows to Linux. So I am
trying to know the WinAPI's used in the code to estimate the effort of porting.


If you're doing a port, you'll have to compile and link the library in to a test application. It will quickly become apparent which functions are from the Windows API.

I don't think scanning a static library is the right way to go about this.
Quote:Original post by rohini chandra
I need to port the static library in question from windows to Linux. So I am
trying to know the WinAPI's used in the code to estimate the effort of porting.

Do you mean you're trying to make the static library binary file usable directly on Linux?

If so, you don't need to worry about WinAPI, since that already offered by the WINE libraries you'll have to link to. If you're trying to use the library directly by Linux software, you're out of luck because the COFF binary format used on Microsoft Windows is not compatible with the ELF binary format used on Linux.

If you've got source for your library you're just trying to make you job harder.

Stephen M. Webb
Professional Free Software Developer

This topic is closed to new replies.

Advertisement