Debugging c++ .cpp file using Xcode
I have a solitary .cpp file, and I would very much like to debug it.
Without creating an Xcode project, is there anyway I can debug this using the Xcode debugger?
When I open the开发者_如何学运维 file in Xcode to edit and set breakpoints, the program doesn't stop at the break points.
You can't debug via Xcode without a project because without a project, Xcode works only as a file editor with color highlight and so one.
For debugging you need an executable compiled with debug option, which is produced via a compiler. The easy way (but in my opinion the worse) is to make a Xcode project and put the .cpp file there. There is the hard way too (and probably the best for future reference) that is to learn to do it on the terminal, using for instance the g++ (compiler) and gdb (debugger).
If noone answers you later, maybe this post will help you
I'm not a XCode developer, but I know, that to debug a process you need:
a debugger
the corresponding (!) code
the info, which stores a special debugging info, which gives the debugger an opportunity to map from binary process to your C++ (or other) code
and the process, sure :)
this link could help to understand if you have debugging info
http://www.meandmark.com/xcode3debugging.pdf
you can search words "Debug Information" and try to understand, if you have it or not
There is a way to do this without floundering through xcode, but unfortunately it is possibly more arcane.
Using cmake (https://cmake.org/) you can write a simple CMakeLists.txt to pull in your cpp file:-
cmake_minimum_required(VERSION 3.10)
project(project)
set(CMAKE_BUILD_TYPE Debug)
add_executable(project code.cpp)
To generate an xcode project type this:-
cmake -G Xcode
this will create project.xcodeproj
You can now type:-
open project.xcodeproj
and xcode will be launched.
精彩评论