Reputation: 3041
I've got a C++ .lib file provided by a vendor, with some sparse documentation and sample code. My task is to use it to build a prototype to showcase the vendor's technology.
Being a (mostly) C#/Java developer, I'm trying to hack together something basic using this lib and using the tricks I know - all of which are leading me to believe I'm missing something (or the lib is...)
dumpbin /exports foo.bin doesn't show any exported functions:
E:\SDKs\Acme\lib>dumpbin /exports foo.lib
Microsoft (R) COFF/PE Dumper Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file foo.lib
File Type: LIBRARY
Summary
1AB29A0 .bss
6BD0 .data
AAE0 .nocopy
C5A0E0 .noinit
1954D0 .rdata
19000 .scratch
C1CA0 .text
492000 .vram
lib /list foo.lib shows a number what I assume are function names with a .w32o extension. Based on the function names, and the type of business the vendor is in, these all look valid.
The vendor's README says to initiate the library by calling its __foo_entry() function. Dumpbin /SYMBOLS does in fact show this function:
040 00002826 SECT1 notype () External | __foo_entry
The vendor's sample code loads the library (using dlopen, which is a *nix way of loading a library according to my understanding.)
But I've created a VS2010 project, and have tried to load the library like so:
System::Void load(){
HINSTANCE sdl_library = LoadLibrary(TEXT("E:\\SDKs\\Acme\\lib\\foo.lib"));
if (sdl_library == NULL) {
Console::WriteLine("error");
} else {
Console::WriteLine("success");
}
}
When the project tries to the line containing "LoadLibrary", the debugger throws a Bad Image exception: "E:\SDKs\Acme\lib\foo.lib" is either not designed to run on Windows or it contains an error..."
Dependency walker is not much help here because the .lib is static.
So: is it a valid .lib or not?
The visual studio command line tools seem to indicate it is valid, but trying to load it into a project indicates it's not.
Upvotes: 0
Views: 488
Reputation: 283624
On Windows, shared libraries and LoadLibrary
are associated with the file extension .dll
.
.lib
suggests that you should try static linking, like a linux .a
file. .lib
files may contain actual code, but are also used for an import library, such that static linking will generate a binary that requires a DLL at runtime.
Upvotes: 2