How to change the location of .pdb files for static libraries? - c++

Now I found out I can change the .pdb file location for C++ executable projects in Linking -> Debugger in the project settings.
How can I change the location for static library projects? As they do not have the Linker menu.
I tried changing C/C++ -> Output files -> Program Database File Name, but without luck. They are still added to the same directory as the compiled executable.

After changing the Program Database File Name, pdb will be added to the specified directory. In addition, if the lib file directories are not changed, another pdb file will also be added aside the lib. This may be why you think it was unsuccessful, but in fact it has been done.

Related

How do I link a library? (MySQL Library)

Alright, I am trying to Link this into my program and I never linked anything before so I need help with not only linking it (Because I have the directory in the linker -> additional directories but I need to link against the libmysql.lib/dll. I am not sure how to do that.
If you could give me a basic understanding that would be great! Just don't make it too complex ;)
I am trying to follow the steps on the website and it says to do this: (I have looked up and people said something about a MakeFile and I honestly don't know anything how that works)
The Connector/C++ static library file is mysqlcppconn-static.lib. You link this library statically with your application. Also link against the files libmysql.dll and libmysql.lib. At runtime, the application will require access to libmysql.dll.
Here's what you need to do to install an library to your c++ project.
Add it to additional depencies in the linker.
Project->Properties->Linker->Input
Click the dropdown, click edit. On the list on the top, add just the names for every .lib file included in the library. For example, If installing SDL, one would add:
SDL2.lib
SDL2main.lib
These files can probably be found under the lib folder of the library you downloaded (look around a bit).
Tell VS where the header files are.
Project->Properties->VC++ Directories->Include Directories
Click the dropdown, click edit. add the location of all of the header files of the library. You can put them wherever you want, but it is suggested you put them in their own folder in your project folder somewhere. Wherever you put them, put the directory here; the containing folder, not the files themselves.
Tell VS where the lib files are.
Project->Properties->VC++Directories->Library Directories
Click the dropdown, edit. Same thing as step 2, but you instead are putting the location of all the .lib files. Yep, the same ones you defined in step 1.
Provide the .dll files to your executable.
When the executable runs, it needs .dll in the same directory or it will not run (CORRECTION = It will run, but will give you an error upon open). So find your executable and put any .dll files in the same directory. How to find where it is by default:
Solution Explorer->Right Click Solution->Open in explorer->Debug
You should see the .exe there. Put the libraries dll files in that same directory.
If you have any questions please ask.

Visual Studio 2012 Update 4 doesn't create PDBs for static libraries

After I installed the 4th update on Visual Studio 2012 I noticed that there is no PDB file next to my C++ static library any more. I can debug the library on my local PC (apparently some information about sorce code location is inside lib file), but when I copy this static library to another PC, VS doen't try to locate source files.
I tried to add source code location to "Solution Property -> Common Properties -> Debug Source Files -> Directories containing source code", but it doesn't help anyway.
Did anyone solve the problem?
Ok, I fixed that.
Actually the pdb file didn't disappear, it just placed in the intemediate directory and had a strange name - vc110.pdb, which made me think that it contains debug information only about standard VC files. Apparently, it contains information about my library as well. Renaming to MyLib.pdb will not work because MyLib.lib file contains reference to the old name. So its name may be changed only via C/C++ -> Output Files -> Program Database File Name.

Why does Visual Studio generate these additional files?

In the output directory where Visual Studio places the compiled executable, there are three additional files of the types *.exp, *.lib, .pdb. I do not need those files and I would like to prevent the compiler from creating them.
This is how my build output directory looks like. I only need the *.exe file.
What are these additional files for? How can I disable that they are generated? If they are needed for the build process, is there a way to automatically remove them after the executable is created?
I am using Visual Studio 2012. If you need additional details, please comment.
EXP and LIB files But I don't want that .lib or .exp file for my COM library! . You could probably set the location of these files in the "Intermediate Output" setting and not have them in your release folder
I'm assuming you are looking to have only the dll and exe files in your final release directory and the *.exp, *.lib, .pdb files left in your intermediate directory as to not clutter the directory you are working in.
Visual Studio 2017
Open properties (Right click on the project in the solution explorer):
change settings as shown:
Import Library will define where the .lib and .exp files are created.
Generate Program Database File defines where the .pdb file is created.
Debug information format -- None will prevent pdb file from being created. Select this option for Release builds.
There some functions inside declared with as __declspec(dllexport).
It means that they are exported and linker thinks that there is a need to link with this dynamic library (no matter it is exe or dll - in general the structure is the same) and creates *.lib and *.exp file

How to set Debug Symbol Path via .props file

After a restructuring of our project, all the 3rd-party libraries ended up in a single system-wide directory. A set of .props files ensures that the include-directories, library-directories, prepocessor definitions, etc. are set correctly upon including such a .props file.
Currently we advise developers to specify the symbol paths by hand using Visual Studio -> Menu Tools -> Options -> Debugging -> Symbols. But when moving the 3rd-party libraries to another folder, or when seting up a second set for testing, we have to change this manually.
Is it possible, and how, to specify the debug symbol path in a .props file? And how?
And of course, is it possible to set the sourcepath (for debugging) in a .props file?
That's not possible. It is a VS setting, not a project setting.
In general it doesn't make sense to have this problem. If these libraries are static link libraries then their .pdb files get merged into the .pdb file for the final executable. If they are DLLs then there needs to be a way for the operating system to find the DLL at runtime. In which case the debugger also won't have any trouble finding the .pdb file for the DLL.
You can diagnose .pdb searching problems for DLLs with Debug + Windows + Modules. Right-click the DLL and select "Symbol Load Information". It shows you where the debugger searched for the .pdb

Static library debug symbols

In VS2010 there is an option to generate debug info for exes/dlls under linker but no such option under librarian for libs. Is the debug info embedded in the static library?
There is an option in the C/C++ properties for Program Database File Name for libs, exes, and dlls. By default it goes into my intermediate directory and is named the project name for libs, but is named vc$(PlatformToolsetVersion).pdb for exes/dlls. What's the pdb from this option and how does it differ from the pdb in the linker option?
If I am supplying a library with libs and headers how do I supply debug symbols to a user of my library?
If you use /ZI or /Zi (C/C++ -> General -> Debug Information Format), then the vc$(PlatformToolsetVersion).pdb is created, which contains the debug info for all of the .obj files created. If alternately you use /Z7, the debug info will be embedded into the .obj file, and then embedded into the .lib. This is probably the easiest way to distribute the debug info for a static library.
I wouldn't advise distributing a static library, however, since it's generally tied to a specific version of the compiler.
Expanding upon previous answers, for those who need the full how-to (VS 2013 minimum).
Note that this should address comments ^^above regarding VS2013 issues.
Method 1: The Program Database (.pdb) Way (/Zi or /ZI)
Static Lib Project: Generate a pdb with same name as your static lib:
Open Solution Explorer from the View menu.
Right click your static lib project, select Properties
Edit Configuration Properties->C/C++->General->Debug Information to /Zi or /ZI
Note that /ZI allows "Edit and Continue" editing during debugging
Edit Configuration Properties->C/C++->Output Files->Program Database File Name to $(OutDir)$(TargetName).pdb
Now compile it, and note where YourLib.lib and YourLib.pdb are.
Application Project: Link your executable with the static lib, and new PDB file:
Again, navigate to project properties, but this time, for your Application project
Again, edit Debug Information property as needed.
Edit Configuration Properties->Linker->General->Additional Library Directories, adding your own "libs" directory, or whatever directory you plan to keep/copy your YourLib.lib and YourLib.pdb files.
Edit Configuration Properties->Linker->Input->Additional Dependencies, adding YourLib.lib (no path in front)
Now copy both YourLib.lib and YourLib.pdb to the directory you specified above.
Method 2: The Embedded Symbols (no .pdb) Way (/Z7)
Static Lib Project: Generate a static lib with embedded debug symbols
As in Method 1, navigate to project properties
As in Method 1, modify your Debug Information, but this time to/Z7
As in Method 1, compile and note where YourLib.lib is generated.
Application Project: Link you executable with the static lib
As in Method 1, navigate to project properties
As in Method 1, modify your Debug Information property as needed
As in Method 1, edit Additional Library Directories
As in Method 1, edit Additional Dependencies
Now copy YourLib.lib to the directory specified in Additional Library Directories
Discussion:
Advantages of Z7? It's simpler, and the "Single-file" way of doing it. All the debug info is in the lib file.
Disadvantages of Z7? File size on-disk, link times, incompatible with "Minimal rebuild" (/Gm) feature, does not allow "Edit and Continue", older format (e.g. older paradigm)
Why don't I specify Debug Information Setting for Application Project? This post is concerned with how to get debug working in static lib code. The same "Method 1 vs Method 2" choice applies for the Application project as well.
I notice in VS2013 it is possible to set the program database file name in the C/C++ Output Files tab. Changing it from the default to something like $(OutDir)$(TargetName).pdb resolves the issue
Static libraries are implemented into the programs that use them.
If the program that uses them is using debug symbols, the compiled library code in that program will have symbols too.
PDB info from wikipedia:
When debug symbols are embedded in the binary itself, the file can
then grow significantly larger (sometimes by several megabytes). To
avoid this extra size, modern compilers and early mainframe debugging
systems output the symbolic information into a separate file; for
Microsoft compilers, this file is called a PDB file.
Weird behavior in VS2012. Building from scratch (or with /A option in nmake) will produce a .pdb file. Now delete the .lib and .pdb and rerun nmake (without /A of course, to run only link) and no .pdb file is output.