What is .lib file contain while generating DLL - c++

I am generating .dll in visual studio 2010. .lib, .dll, .pdb files are getting generated in output folder.
why .lib (is it static lib?) is genarating along with dll, what is the use of it and
what it contains actually ?
(In linux along with .so it can not have any other files, but why in Windows).
what is this .pdb files, what it contains and how will it be usefull ?
Thanaks in advance :)

.lib alongwith .dll is not static library. It tells the linker that the functions present in lib are to be loaded from the dll. By this, it creates dependency on the dll. Failing to find the dll will cause application to quit (which is checked at the time of start).
It is used in implicit linking of dll.
PDB file is used by debugger to find symbol information.

Why .lib (is it static lib?) is generating along with dll, what is the use of it and what it contains actually ?
No, that .lib is a import library and it is used in implicit linking.
What is this .pdb files, what it contains and how will it be useful ?
PDB file contains Symbol & line information and they are used by debugger to map hex/oct addresses to function names. PDB file is generated when your build your project.
without PDB your program stack trace would look like this
0x00002130
with PDB
0x00002130 yourprogram!function

Related

VS2015 "no symbols loaded for this document" for .lib file

I have an issue where I have a .dll file that is compiled in debug. It statically links with a .lib file, which is also compiled in debug. The source is available for all of them. However when I run the .dll and attach VS to the process it can only step through the .dll's own function but not the ones in the .lib.
In the module view I can see that symbols are loaded for all the modules. How can ensure that .lib has symbols associated with it as well? As I understand because it is linked statically the symbols for it should be generated when compiling the "parent" .dll, is that correct? So is there something I need to do when building the .dll to make sure that ALL functions can be stepped through?
You need to add the location of the pdb file of the LIB you just built for the debugger to find the symbols in the appropriate Tools/Options section (usually the same directory as the output LIB).
Then, you can add the location of the source files in the according Solution Property page :
Then, Visual Studio debugger will find all appropriate information. It will load symbols and be able to jump into the LIB source code when appropriate.

C++ Symbols not found

I'm trying to compile 3 projects:
A static library (.lib)
A dynamic library (.dll) that uses the .lib of the static library.
An application (.exe) that uses the .dll of the dynamic libaray
However, when trying to compile the .exe and setting a breakpoint, I get the warning "The breakpoint will not currently be hit. No symbols have been loaded for this document."
Well, I know that Visual Studio is missing the .pdb files somehow. However, I don't get why Visual Studio doesn't find it.
The .pdb file of the static library is being generated and is in the same folder than the .lib.
The dynamic library references the folder where the .lib and the .pdb of the static library are inside. A .pdb file is created in the same folder where the .dll is created for the dynamic libary.
The application copies the .dll and the .pdb of the dynamic library before compiling to the folder where the .exe is generated.
Still, Visual Studio is complaining that it doesn't have loaded any symbols. In the output console, it also tells me that it has loaded the symbols of the .exe and the .dll, but not of the .lib. Am I missing somewhat?
When you compile the .exe, you should still link to the .lib file that has been generated when compiling the .dll (so I am speaking about the .lib that comes with the dynamic library, not the one that comes with the static one).
Depending on your visual studio version you might configure that here:
Project->Properties->Configuration Properties->Linker>Input->Additional Dependencies
What version of Visual Studio? Are all the projects in the same solution? If so, Just add the library as a reference to the DLL, and the DLL as a reference to the EXE. Then Visual Studio handles linking everything up, and the .exe, .dll, and .pdb files should all be in the solution output directory.
Also, if you use LoadLibrary to load the DLL the debugger won't load the debug info and won't know where to set the breakpoints in the DLL until after it is loaded, which can cause the error you are seeing as well.

How link .obj files in Visual Studio?

My problem is:
I have compiled LuaJit with VisualStudio and its genereated a .Obj file, a dll and .lib file.
i just want to link the .obj file in my win32 application to generate a single EXE file.
If its possible,i still need to add the Lua headers?
Thanks anyway.
Use the header file to define LuaJit symbols for your code that deals with Lua.
To link you only need the lib and dll. Add the lib file to your link dependencies under Project Properties > Linker > Input. Put the DLL next to your EXE when you run.
You need to make the project produce a .lib file containing the code (instead of in addition to the dll) and link that. It could be that you can by switching the project setting (look for one labelled lib, or static). Otherwise, you'll have to modify the project settings. (set output type to lib rather than dll).
I never tried linking a .obj file directly, it might be possible. Lib files are more standard.

Compiler PDB file and the Linker PDB file

I am getting confused as to what is the difference between the compiler and linker PDB files respectively (i.e. in Visual Studio, Project Properties > C/C++ > Output Files > Program Database File Name vs Project Properties > Linker > Debugging). I have tried to find the answer online and so far I know (may be wrong) that a PDB file by the compiler is generated for obj files while the PDB file by the linker is generated for the binary (exe or dll) and is the one used for debugging.
If that is not true, please explain the difference. Either way, what to do when I am creating a DLL where I have the option to select the output PDB file for the compiler as well as the linker and what to do when I am creating a LIB file where only the compiler generates the PDB files as there is no linking performed.
Background: The libraries/dlls are used by several projects, which then need the PDB files for debugging. In the case of a lib file, there is no ambiguity as there is only one PDB file generated. But in the case of a DLL however, do I need both the PDB files to properly debug or just the one generated by the linker?
I honestly don't know what exactly the .pdb file generated by the compile step is used for - I assume that it's some intermediate information the gets pulled into the final .pdb file by the linker.
However, the bottom line is that for debugging purposes all you need is the .pdb file that is produced by the linker.
Update: A little digging netted this from http://blogs.msdn.com/b/yash/archive/2007/10/12/pdb-files-what-are-they-and-how-to-generate-them.aspx:
What are the two types of .PDB files?
==============================
There are two types of PDB files. One
generated by the compiler named as
VCx0.PDB(e.g. vc80.pdb), and another
the .PDB.
The VCx0.PDB file is generated by the
compiler and it is related to the .OBJ
file. It contains the type information
only.
The .PDB files are
generated by the linker and it is
related with the target executable or
the DLL. This file contains the
complete debug info. When we are
debugging, we need this ‘.pdb’ file
for aligning to the symbols. The
timestamp of the target file and the
PDB should match.

How do i add .pdb file associated with a lib file?

How do i add .pdb file associated with a lib file?
I am importing a .lib file in a C++ project. When I build it i get an error saying that vc90.pdb does not contains the debug information.
I have the pdb file associated with the library. how can i add it to my current project.
Thanks
We just have the pdb file sitting in the same directory as the .lib file with the same name (ie. foo.lib and foo.pdb) and the compiler appears to pick that up automatically. We don't explicitly point anything at the .pdb files.
I think vc90.pdb is VS2008's fallback if it can't find one with the same name.