How to debug dylib with Xcode?
I have a Xcode project for library arith. I could build it with debug configuration, and I need to debug it. How can I do that?
The ideal method would be to set up a test code to build an execution in a project file, and then set a breakpoint in a source code in arit开发者_StackOverflowh library.
However, it seems that Xcode arith project doesn't allow to add another use_arith project that uses the arith library.
What method people use to debug a dynamic library in Xcode?
ADDED
I googled and found some ways to debug dll. Attaching to a running process can be one way of debugging dynamic library. And, for iPhone/iPad programming dynamic library is not allowed, so static library is used.
Attaching to a Running Process - http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/Attaching-to-a-Running-Process.html
Debugging a library with Xcode - Debugging a library with Xcode
Easy, Modular Code Sharing Across iPhone Apps: Static Libraries and Cross-Project References - http://www.clintharris.net/2009/iphone-app-shared-libraries/
I could find a way to debug dynamic library in Xcode.
Build
- Make a library, I'll call this arith library. Debug build to make libarith.dylib.
- Make a project to use the library, I'll call this usearith.
- For userarith, Project->Add To Project, and add the arith library.
- Open Project info, and open the Build tab.
- Go to Search Paths/Library Search Paths, drag and drop the arith library. You should remove the library name as you need only specify the path. Specify the header directory with 'Header Search Paths'.
- Go to Linking, set Other Linker Flags, add -larith
Running
Now, you should be able to link the execution binary to the library. For running, you need to copy the dynamic library to the directory where the execution binary is located.
Debugging
You need to set the breakpoints both arith/usearith. You can run debugger in arith and use the step into to debug the code in a arith project.
I faced the same problem and no one of the previous answer worked for my case so I share my solution (for Xcode):
If you need to debug a c/c++ dylib which is loaded by an external (executable) program:
- First be sure that your dylib is build with the same architecture as your external program.
- Then Go to --> Product —>Scheme—>Edit scheme
- Got to Tab Run(Debug) and check "Debug Executable" , then select into the dropdown button your external program as executable. Then check "Launch Automatically"
- Additionally if you program needs extra argument you can add it into the "Arguments" tab.
- Finally you set some breakpoints to your c source file and finally click run.
精彩评论