VS2015 "no symbols loaded for this document" for .lib file - c++

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.

Related

Is it possible to debug into a DLL with only a PDB and no source code?

I'm trying to debug an exe that calls a dll, in Visual Studio. I made sure I had the corresponding pdb in the same path as the dll.
But I cannot get into the functions that the dll is offering.
I get a message that says "xyz.c was not found"
Why am I getting this message?
Does this mean that I can't get into the source code just from a DLL + .PDB?
What about a static library (.lib) built using the /Z7 option?
No, you need to have source code to be able to see the source code.
pdb (or /Z7) contains debug information which is like mapping between executable code and your source code. With pdb VS debugger knows where in source files each instruction is located, but it still needs to have source files to show you the code.
Usually pdb file stores location of source files and VS debugger knows where to find them. If you move src files somewhere else then AFAIK VS will show a popup dialog to browse for .c/.cpp file that it cannot find.
Yes, you need the source code to source debug. The .PDB only contains symbols so you will be able, for example, to view a stack trace or determine the source file name and line number of a crash. Otherwise, you need the source code.

Step into source code of linked library

I got some compiled C++ libraries (.lib, not compiled by myself) which I link in my own C++ project. I also got the source code.
Is it possible while debugging to step into functions from those libraries using the source code? How can I tell the Visual Studio debugger to use those source code files?
I guess that .lib files would need some kind of debugging information - can I find out if they got those?
Microsoft compilers store debugging information in separate .pdb files. When VS loads a library (say myLib ) used by an executable ( either by attaching to a running instance, or by starting it directly under debugger), it also searches for myLib.pdb. If it finds it, when you try to step in such a function, it will first ask you the location of the source corresponding to it. If it is correctly provided, you will be able to debug it.
Without .pdb files, I do not know any way to debug the external library at source code level.
Also, if there are no .pdb files, but you do have the source code for the external library, would it be possible for you to re-build it with debugging symbols (.pdb files ) ?

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.

What is .lib file contain while generating DLL

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

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.