user25101622
user25101622

Reputation: 193

Are .lib files useless without the header files?

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

Answers (2)

Ben Voigt
Ben Voigt

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

Jonathan Henson
Jonathan Henson

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

Related Questions