Reputation: 193
I have some .lib files, but I do not have access to the .h header files. Does this mean the .lib files are useless now?
If not, how can I use them again?
I tried using this line in my program, but it doesn't seem to be compiled into the final executable (verified with CFF Explorer).
#pragma comment(lib, "SomeLibFile.lib")
So, the only way to link .lib file is through the use of its header files? Are there any tools to recover a header file for the .lib file?
Upvotes: 6
Views: 4609
Reputation: 283614
You can link with a .lib
file by passing it on the linker command line, no #pragma
is necessary.
Of course, actually using anything inside it requires knowing calling conventions, function signatures, layout of user-defined types, etc. That's all usually provided by a header file, but could also be found in documentation.
In any case, header files are not compiler-generated (well MIDL and CORBA do use machine-generated header files, but all the information in the header is still manually entered into the .idl files). And unless your technology uses a type library, the needed information is not kept with a DLL.
Upvotes: 2
Reputation: 8206
It depends on how the .lib file code was written. If it is a c api, this is what the extern keyword is for. You could find some sort of program that would show you the function exports. Then you could declare them as extern in your code. The problem would be your data structures though.
Anyways, you don't technically have to have the header files, you could define the data structures on your own, and declare the functions with the extern keyword.
You could just link the .lib when you run your linker at the end of your compilation process.
Upvotes: 5