0

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.

drescherjm
  • 10,365
  • 5
  • 44
  • 64
db7638
  • 410
  • 6
  • 17
  • 1
    You need a visual studio project. Open the project, then build then you can debug. – drescherjm Jun 27 '17 at 21:31
  • ***CMakeLists.txt files*** That is what you need. Use `CMake` to generate a Visual Studio project. Hopefully the source supports Visual Studio. – drescherjm Jun 27 '17 at 21:32
  • @drescherjm Could you please elaborate a little more on how to use CMake to generate a Visual Studio project? I haven't used CMake before. – db7638 Jun 27 '17 at 21:33
  • ***How do i add these dependencies?*** It would most likely not be easy for you to manually do that. Thankfully you have a `CMakeLists.txt`. – drescherjm Jun 27 '17 at 21:35
  • read https://stackoverflow.com/questions/395169/using-cmake-to-generate-visual-studio-c-project-files – Öö Tiib Jun 27 '17 at 22:21
  • @drescherjm Thanks, that worked out for me. – db7638 Jun 30 '17 at 18:23

1 Answers1

0

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.

geza
  • 28,403
  • 6
  • 61
  • 135
  • There may not be a PDB file until after using the CMake to create a project and build from source – Dave S Jun 27 '17 at 22:33