How to debug a bundle in XCode? - xcode

I wrote a nice little program. At some point, it is required to load a bundle with some additional functionality. I, too, am the author of the bundle, so I have the source code and Xcode-projects for both the main application and the bundle.
Until now, I simply dragged the bundle into the resources-folder in the main application, which works fine for running it, but I can't debug it (and of course there is an error in it).
Is there a way to set up Xcode so that I can debug the bundle?

In your bundle project, you should add a custom executable. That executable will launch in the debugger when you do a Build & Debug.
To do this in Xcode 3, right-click on the Executables section in the Groups and Files list in your project and choose Add > New Custom Executable…
You can then select your application in the open dialog.
In Xcode 4, you need to go to Product > Manage Schemes, select your Debug scheme and in the Info tab for the Debug action you should use the Executable popup to choose a custom executable.
You will also need to change your build settings for your Debug scheme so that the build products are placed in your application's plug-ins folder when the plug-in is built, so that when you Build & Debug the application contains the latest version of your bundle.

Related

Adding an external executable in Xcode 4

I would like to debug Firefox code on OS X.
I'm reading from this page and it tells me:
Now you need to add the executable. Select Project > New Custom
Executable and type a pretty name, then click the Choose button to
locate the .app file that you want to debug (Mozilla.app, Firefox.app,
DeerParkDebug.app etc). The .app file is
But with xcode 4 there is no Projects menu. I can't seem to find out how to add a custom executable. I have successfully built Firefox but I just can't debug it because I don't know how to add an executable in Xcode 4. I suspect the steps in the link were for Xcode 3.
Under Xcode 4 you will have to edit a scheme to run an executable. Select a scheme (or duplicate one for your target) then select the "Run" phase. You will see an "Executable" pop-up menu, select which executable you wish to use then run your target. There are other settings for specifying the arguments, etc just as in Xcode 3.

Xcode: Multiple targets in same bundle

I have an Xcode project with a Cocoa application target and a shell tool target. These projects share a Core Data persistent store and thus I am hoping to have both projects use the same *.mom file.
To allow this and to simplify deployment I would like the terminal app to to placed inside the Cocoa app bundle and then have both executables access the same *.mom file from inside the bundle.
Is it possible to setup the Xcode project so that the terminal app gets placed inside the Cocoa app bundle and then have the terminal app load the main bundle of the Cocoa app to get the path of this shared *.mom ?
You should be able to do what you want.
Make the Cocoa app target dependent on the terminal app target: click on the Cocoa target, Get Info, General Tab, and click the "+" under the Direct Dependencies pane, and select the terminal target.
Add a "Copy Files" build phase to your Cocoa target: right-click on the target, Add -> New Build Phase -> New Copy Files Build Phase. You'll get an information window where you can pick the destination of the copy; I recommend "Resources", the default.
Drag the terminal app build product (from the "Products" folder in the project navigation pane) onto the Copy Files build phase you just created. This will cause the terminal app to be copied into the Cocoa app's resource folder, which is where your .mom file lives by default, at build time.
In your Cocoa code, you can find the path or URL to the terminal app by querying the main bundle for the path to the resource with the terminal app's name and extension. Your terminal app will need to discover the directory that it is launched from to find the .mom file in the same directory.
Hope this is helpful.

Command line tool to add resources to an Xcode project

I've got an Xcode project that creates a standard application that can be branded in multiple ways and contain some custom content. At the moment I have a Resource "Resources > Tour Packages" with the custom files under this. At the moment every time I want to brand the app a different way I have to delete the old files from this resource and then manually add the new versions via the XCode UI. I can't post and image but it is here - http://img.skitch.com/20100121-xub48r6e1p857c84hdrgg25dw6.jpg).
My Question: Is there a command line tool that performs the same operation?
You'd probably be better off just creating multiple targets in your Xcode project, and associating the resources for each branded version of the app with one target.
To do this, just right-click on your target and select Duplicate. You should then remove the custom resources from the Copy bundle resources build phase. You can then add a new set of resources to the Copy bundle resources build phase that are specific to the new target. You can then build any target you like by selecting it from the Active Target popup in the Xcode toolbar or by selecting it in the Project > Set Active Target menu.
This way, you can easily build different versions of your app without having complete duplicates of all your source, difference Xcode projects etc.
Yes, the xcodeproj ruby gem allows you to add resources. https://rubygems.org/gems/xcodeproj/versions/0.28.2

How to start Xcode debugger for a project without any executable?

I have a Xcode project that is building a library and I want to be able to debug the library when it is loaded by the main application.
Run and Debug options from Run menu are disabled and if i try to use attach to process option I get "No launchable executable present at path". When looking at Active Executable I see but I don't know how to tell xcode what to run/debug.
So how should I debug the application? I'm looking for something similar to the project configuration of Visual Studio but I wasn't able to locate this option yet.
Add a custom executable to your project.
It is under the Project -> New Custom Executable... menu item.
From there, you can add your application as the custom executable and that will give you the ability to debug the application and the plug-in.
One additional helpful hint; in Xcode's build preferences set up a single common products directory. This will put the symbol files for building your application in the same directory as your application (assuming your main application is one you build) and, thus, you'll be able to step through frames in both your library and your application.
For those using Xcode 4:
Project > Scheme > Edit Scheme...
Select the Run phase > Info
And set an Executable

Bundle framework with application in XCode

I am an XCode novice. I am trying to follow these instructions. Clearly I am missing something because while I can see that the framework I want has been copied into the app bundle, I can't reference it.
When I start the application from a machine other than mine (or if I remove OpenCV from /Library/Frameworks/ ) I get the following error:
Dyld Error Message: Library not
loaded:
/Users/david/Library/Frameworks/OpenCV.framework/Versions/A/OpenCV
Referenced from:
/Users/g/Demo/Slates/ClipSplitter/build/Release/ClipSplitter.app/Contents/MacOS/ClipSplitter
Reason: image not found
There is no user "david" on my system if that makes any difference. Also this is a prebuilt OpenCV downloaded from the internet. (Here’s a screenshot of the project as requested in comments.)
When the OpenCV.framework has been build it has been configured to use an install path of /Users/david/Library/Frameworks/.
Since you want to use the library as a private framework (installed in the application wrapper at ClipSplitter.app/Contents/Frameworks/OpenCV.framework) you have to change its install path. This can be done easily using the terminal as follows:
$ install_name_tool -id #executable_path/../Frameworks/OpenCV.framework/OpenCV <your_path>/OpenCV.framework/OpenCV
Of course you have to adjust the path of the last argument.
Now, when linking your application, your modified framework tells the linker that dyld has to search for the OpenCV.framework in the app wrapper of your application (in the ClipSplitter.app/Contents/Frameworks directory).
Now you have to copy the OpenCV.framework to your application wrapper. You can do this as part of your build process by adding a copy files build phase: Right-click on your target, select Add->New Build Phase->New Copy Files Build Phase. Select "Frameworks" from the "Destination" pop up and close the dialog.
Your target will now contain a new phase to which you can add the OpenCV.framework by dragging the icon from the Project Navigator on the left side of Xcode window. Note that Xcode won't allow you to add a folder to the Copy Files phase by using the '+' button so in order to copy the framework you'll have to drag&drop it.
You need to set the build setting "Installation directory" to #executable_path/../Frameworks
See the chapter about Embedding a Private Framework in Your Application Bundle in https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html
Regards
Using Xcode 5, you can facilitate this using the Build Phases panel of your application target.
The default appearance of this panel is
By pressing the "+" button underneath Copy Files, you can add your framework as a file that will be copied into Frameworks in your app bundle.
Now, when you build, your Framework(s) will be copied into your bundle.

Resources