How do I debug existing C++ source code in Visual Studio 2015? - c++

This may have a very simple solution, but being new to Visual Studio and C++ programming, I'm having a hard time with this.
I downloaded an SDK written in C++ which contains an executable file and also the source and header files. The executable file accepts some command line arguments. So far I've been running the executable file from the windows command prompt (like C:\path\filename.exe -argument), but now I want to be able to enter these command line arguments and then place breakpoints in the source code for debugging the source code.
I don't know how I can open the source files in Visual Studio and debug it. If I just open the source file with the main function, the debug button says 'Attach' on it instead of debug.
I see another similar question here, but that question is for a project developed using Visual Studio whereas the source code I have does not have any Visual Studio project/solution files. The only files I have are the executable, the source and header files (.cpp, .h, .hpp), and CMakeLists.txt files.

You can "open" the exe as a project (you can achieve the same if you drag and drop the exe into VS icon). Then you can add command line parameters at Project Properties. You will need to have debug symbol information (usually a .pdb file), if you want source code level debugging (values of variables, etc.). If you don't have that, you can only debug at the disassembly level.
You may want to create a proper project for the source files - it is an easy task, if the project is simple - so you can rebuild the exe.

Related

How do I run .cpp files in Visual Studio?

I have been following tutorials which have me download and unzip projects which contain .sln files for me to open. Following them this way is pretty easy. However, I want to be able to download a single .cpp file and run it without creating a project. I just want to get straight to into it. In Code::Blocks, setting this up is easy to figure out. For some reason, I can figure it out in Visual Studio.
I want to be able to download a single .cpp file and run it without creating a project.
You cannot. Visual Studio does not support this. A project is always required, even if it only contains a single source code (.cpp) file.
You can, however, run a single .cpp source file through Microsoft's C++ compiler on the command line (cl.exe), and then execute it. But this doesn't involve anything about the Visual Studio IDE.
if you have the source code, you could make a .cpp file by right-clicking and adding one and then ctrl+s then f5 and it might run... Idk.

visual studio 2013 modify path variable when running .exe

I have compiled an exe file in Visual Studio 2013, and it depends on some external files to function. I want to keep those files in the same folder that the exe is in. When I run the .exe by clicking on it in file explorer, it loads the files fine. However, when I run it from Visual Studio, it is unable to run because the PATH variable does not include the directory with the necessary files. How can I configure my project to run the program with a modified path variable so that it can access the files properly?
As far as I understand you question correctly. I suspect that this is an issue related to the different directories when you execute. In Visual Studio (to my knowledge), you have a folder named Debug and a second folder named Release.
You may choose in Visual Studio to run the program in either debug or release mode. But you might not have the required files neccessary in both directories.
For example:
I've made a program that reads "Hello World!" from hello.txt, and displays this in the dialog window as a string.
If I store the file in the Release directory, the executable will run fine outside the IDE, when just launching the executable file.
However, if you run the application in debug mode through the IDE (Visual Studio), the program will not find the neccessary file. The program is looking for the file in it's current directory (Debug).
A quick fix to this is to copy the required files to the current working directory. Eventually have a duplicate set of files in both directories at all times.
Hope that I did understand you correct, and that my answer helps you. :)

How to tell Visual Studio to use a different source code directory to debug into a library?

I provided clients with a C++ class library that they use in one of their C++ project.
They want me to investigate when a specific assert happens in the library, and sent me their client code to debug it.
I reproduced the assert on my computer, and was prompted by Visual Studio to specify a directory containing the source code to the library, for debugging.
I selected my development directory, but noticed that when navigating the call stack in Visual Studio, it directed me to wrong places in the source code. I realized this was because the directory I notified contained newer source code for the library (not the source code that was used to build the library that was sent to the client).
Fortunately, I have the source code that was used to build the library that was sent to the client. Unfortunately, I do not know how to tell Visual Studio to use this source code directory instead of the one I erroneously specified before.
How can I change it?
Try changing the name of the directory...
This should force Visual Studio to ask again for a directory, since it will no longer be able to find the code...
Try editing the Debug Source Files page.
This property page specifies where the debugger will look for source files when debugging the solution.
To access the Debug Source Files property page, right-click on your Solution in Solution Explorer and select Properties from the shortcut menu. Expand the Common Properties folder, and click the Debug Source Files page.
Source

Cannot step into the code while debugging a C DLL file in Visual Studio 2012

I have a separate Visual Studio solution with the DLL written in C. I use it in another solution; in a console C++ project. While debugging the console project I step into a DLL function.
However, the page is opened reporting that There is no source code available for the current location with call stack location MyConsole.exe!_tailMerge_MyLibrary_dll(). I use delay loading of the DLL file in the console project. As the no source code page is displayed, I inspect the output window and find symbols loaded of the DLL line. Why does Visual Studio 2012 fail to step into this DLL code?
I had the same problem and the following solved mine. I set "Debugger Type" to "Mixed" on the properties page of the main project. My main project is managed code while the .dll is native.
It happens, when dealing with external projects that Visual Studio asks you if you have the code. If you cancel the process, the requested file gets added to a list in the solution and it remembers NOT to ask for the file again.
Check your Solution Property Pages > Debug Source Files. First, make sure your file is NOT in Do not look for these source files: and then make sure you add the location of the sources in the Directories containing source code. This should help fix the problem.

Problem creating static/dynamic c++ libraries in visual studio

When I try to build my c++ library (in both static and dynamic mode) using visual studio 2008, in the debug folder, instead of .lib or .dll file, some .obj files are created along with an .idb and an .pdb file.
how can I make visual studio build the library file?
You're either looking in the wrong place or there's a problem in your build.
Open the BuildLog.htm file that VS creates when it does a build (there should be a link you can click in the Build Output window). It'll tell you where it's putting the file. Look for the line containing an "/OUT:" option.