Are .lib files useless without header files?

I have some .lib files, but I do not have access to the .h header files. Does this mean that .lib files are now useless?

If not, how can I use them again?

I tried to use this line in my program, but it does not seem to be compiled into the final executable (verified using CFF Explorer).

#pragma comment(lib, "SomeLibFile.lib") 

So, the only way to link the .lib file is to use its header files? Are there any tools to restore the header file for the .lib file?

+6
source share
2 answers

It depends on how the .lib file code was written. If it is c api, this is the extern keyword. You may find some kind of program that will show you the export function. You can then declare them as extern in your code. The problem will be in your data structures.

In any case, you do not need to have header files; you can define the data structures yourself and declare functions with the extern keyword.

You can simply bind .lib when you start your linker at the end of the compilation process.

+5
source

You can link the .lib file by passing it on the linker command line, #pragma is not required.

Of course, actually, using something inside, it requires knowledge of conditional conventions, function signatures, layout of user-defined types, etc. All this is usually provided by the header file, but can also be found in the documentation.

In any case, the header files are not generated by the compiler (it is good that MIDL and CORBA use machine header files, but all the information in the header is still manually entered into .idl files). And if your technology does not use a type library, the necessary information is not stored in the DLL.

+2
source

Source: https://habr.com/ru/post/908243/


All Articles