I've created a working Cocoa framework which I wish to redistribute. The problem is however, it won't run outside of Xcode. I've read something about #executable_path/../Frameworks, which I did not include, because I don't know where to put it :/
Therefore I run my app in Xcode using the DYLD_FRAMEWORK_PATH variable which works fine, but only in Xcode - if I try to run it on its own it crashes straight away and says IMAGE NOT FOUND.
I'm sure #executable_path/../Frameworks is what's missing, but I don't know where to put it.
Could anyone help me out please? :)
Thanks
Here is how I usually manage things:
In the framework's Xcode project, set the Installation Directory to #rpath
Add the framework to your application's Xcode project. Add a Copy Files build phase, select Frameworks in the Destination popup, and ensure your framework is added so it will be copied to your application's Frameworks directory when it is built.
Finally, in your project's settings, add #loader_path/../Frameworks to Runpath Search Paths.
Are you actually copying the framework into your applications bundle? Look for the folder called MacOS which is what contains the binary. There should be another folder at the same level called Frameworks and it should have the framework inside it.
If it's not there you need to create a copy files build phase for the application that copies the framework into the Frameworks folder.
Related
Goodday!
ToDo: compile the files from a directory that is outside of my Xcode project.
How to tell Xcode the path to look for source codes to compile (like the VPATH in a makefile)?
Note1: Right-click the target and it is easy to add the search path for header files or lib, but there I havent found any option to add a new source code directory.
Note2: I havnt found an answer in the xcode build documentation for this issue.
P.S.: I hope that I can do it without copying all the files to the xcode explicitly.
Thank you!
Drag the directory containing the files into your Xcode project. The only way Xcode knows it needs to compile the files is if they are contained in the project and a part of the target.
You indicated that you wanted to use at least some of the source files in a project and intend on using some set of the same source files for other future projects.
Create a new static or dynamic library using the external collection of source files and then just link this project to it and future projects to it
The design of most build environments encourages the use of code in reusable libraries.
Davidli
By the way (for those who are still searching and have problems with this issue), i have Xcode 4.5.2 and when i drag the items they are not linked! It seems that xcode's getting worse with each new version.
In case of xcode 4.5.2 if i copied class files into the separate folder i had to do right click to the group and choose 'add files to ""'
[UPDATE 03/04/2015]
The question is now 4 years old, and applies to a specific version of XCode which I have now specified in the subject.
I have searched a lot for this argument, but I couldn't find a solution, I even post on stackoverflow, but I soon deleted the question becuase of very little access.
Now I am trying again.
I have a workspace with two distinct projects A and B.
B has two targets, one that build a static library Blib.a, and one that build a bundle B.bundle. All of them get built in the derived directory.
In project A I can easily add the static library from the build phases. However I cannot find a way to include the bundle. B.bundle is not visible from "copy resource" tab in A.
Therefore I need to add manually, with all that implies.
I also thought about using a script, but I would like to use this as a very last option.
Has someone a solution for this ? Did I miss something ?
thanks
After long investigation, it came up there's no easy way of doing this. The B.bundle is never visible to A project, and there's no settings in workspace to change that.
At this point there are three solutions:
Include the bundle manually from "copy resources->other", I started with this, but everytime there's a change you have to drop and include the bundle again
Create a script to be run in build phase, if everything is built into the PRODUCTS dir you can find the bundle easily and having copied automatically into the app.bundle. This is not a bad solution. If you are using svn the script got included in project, and users have it for free without additional work.
As suggested by Apple tech support, use folder references.Build bundle B into a folder and add such folder to project A using the "Create Folder References for any added folders" option. Xcode 4 will update your bundle into that folder every time you built it.
The added folder will appear as blue once included in your project A.
Thats's it, I personally use the script, because this solution is path independent if you use standard xcode reference variable such as BUILT_PRODUCTS_DIR and so on, and the shell script is just a cp -r-f
[UPDATE 03/04/2015]
I would like to point out that the question is now 4 years old. At that time there weren't many "official" options available. I even spoke with Apple Tech Support, which proposed solution 3 as the only available solution. It is of course very likely that things are now changed, and there is a much better solution. Just to speak, I also like to add that the three above are not "hacks" but "solutions", maybe technically outdated, but they can still be used nowadays. I intend a "hack" as a..."hack", which means it probably not going to work in future software release.
Here is how I did it.
Drag and drop B.bundle from Project B → Products → B.bundle into the Copy Bundle Resources build phase of your app in Project A (select the Create groups options when asked). This will add B.bundle at the root of your Project A outline. You can move it into the Frameworks directory near Blib.a if it you prefer.
Select B.bundle and check its Location in the Identity and Type right panel (Utilities area). By default, Xcode chooses Relative to Project. This is wrong, select Relative to Build Products instead.
The path to B.bundle will now look something like ../../../../../../../../Projects/MyApp/B.bundle. This is not what you want, but you can easily fix it. Open ProjectA.xcodeproj/project.pbxproj in a text editor, search for this path and delete everything in it except for B.bundle. Your project.pbxproj should look like this:
explicitFileType = wrapper.cfbundle; name = B.bundle; path = "B.bundle"; sourceTree = BUILT_PRODUCTS_DIR; };
Save your project.pbxproj file. Xcode will automatically reload your project and your app should build just fine.
After searching for a long time and failing many times, I found this resource that has been an absolutely great tutorial to create Static Libraries and include bundles in your main project or even for distribution to 3rd party developers that may consume your library.
Absolutely recommended:
https://github.com/jverkoey/iOS-Framework
In project A, is the product of project B a dependency in your scheme's Build action? I think you might have to set up this dependency (sometimes disabling the automatic dependency discovery option is best) for it to show up and be available for copying into another target. I believe this is because it doesn't really exist (like an image resource file) until it's built and Xcode needs to ensure it's built before working with it from another target.
As of Xcode 5.1.1 I was able to drag and drop B.bundle from the Project Navigator to the Copy Bundle Resources list of project A Build Phases. I assume creating B.bundle target is not an issue.
Switch build to Generic iOS Device. This step is needed to create a non-simulator reference.
Drag the .bundle to the other project's Copy Bundle Resources.
Select the .bundle in the Project navigator of the other project, and change its Location to Relative to Build Products
Make sure your .bundle in added to Target Dependencies of your static library
Many people including me trying to make a kind of Static Library framework for iOS to archive some kind of modularity. Framework is best way to do this, but it doesn't provided by Apple, and workarounds don't work well.
https://github.com/kstenerud/iOS-Universal-Framework/tree/master/Fake%20Framework/Templates
Fake framework cannot be referenced from linking tab in Build Phases.
Real framework needs modification of system setting. And still not work smoothly on every parts.
Problem is static library need header files, and it's impossible to reference header files on project at another location on different project without some script. And script breaks IDE's file management abstraction.
How can I use static library project like a convenient module manner? (just dragging project into another project to complete embedding)
I've since updated the template to do away with the script target. It now builds the universal framework from your regular target, so you can include it in workspaces or as a project dependency.
With a real framework target, you can just add it to "Link Binary With Libraries", and it will show up fine.
With a fake framework, Xcode doesn't recognize the target type, so you need to add the link command manually. For example, assuming your framework is called Foo:
Expand the "Products" group of your framework project, then drag "Foo.framework" into the "Link Binary With Libraries" build phase of your app target.
In your app target, edit "Other Linker Flags" in the build settings and add: "-framework Foo"
Framework template link for anyone not sure what we're talking about: https://github.com/kstenerud/iOS-Universal-Framework
Solution.
Goto Project or Target's Build Settings.
Find Public Headers Folder Path. (definition name = PUBLIC_HEADERS_FOLDER_PATH)
Set it as YourLibrary.framework/Headers. I have used ${PRODUCT_NAME}.framework/Headers for automatic syncing with project name.
Goto Build Phases and find Copy Headers step.
Move all required headers to Public pane.
Now all header files will be formed like Framework and copied with product binary. IDE will copy all of them as a unit into some temporary folder like app's build folder. So referencing app project can use the headers automatically.
This is a trick. The created directory structure is not real framework. Because it doesn't contain any binary. However we don't need real framework to archive just this functionality. IDE works with frameworks without any binary. And I don't want to hack IDE without documentation about internal structure.
This works well, however you'll experience some problem when you Archive. This happens because Xcode4 behaves specially when Archiving. Here's workaround.
For each embedded library project, SKIP_INSTALL = YES in target build settings.
For final product project, FRAMEWORK_SEARCH_PATHS = "${OBJROOT}/UninstalledProducts". Take care about this setting should be set only for Release build mode.
Now it'll be archived well.
At the case of cross platform library, there can be many projects for many platforms. But sometime Xcode will show some product as red color even it compiled successfully.
This is a bug of Xcode. IDE display depends SDKROOT of Project build setting. So if you set the SDKROOT differently on Target, it won't work. You can check the the product will become black color after changing the SDKROOT of the Project build setting. See this Open Radar entry for details.
http://openradar.appspot.com/9636211
If you wish to fix this bug, please report this to Apple's Radar. Duplicated bugs will make attention of Apple. Just copy & paste my report :)
I found this : http://db-in.com/blog/2011/05/creating-universal-framework-to-iphone-ios/
It seems to work.
I have created IB kit plugin now i want to use that plugin in other Xcode project
how to do that? I have tried developers guide but not able to get that done ..please answer
First of all, I assume that you want your plug-in to be embedded within your application's bundle. If not, you can place the IBPlug-in framework in a standard location like /Library/Frameworks.
Creating the Plug-in
Once you have an IBPlugin project created in XCode using Apple's template, you need a little tweak:
Change the name of your framework target so it differs from the Plug-in's. For instance, you could call it MyIBPluginFramework.
In the Target Properties > Build : Modify the Installation Directory of MyIBPluginFramework to #loader_path/../Frameworks.
Also set its Dynamic Library Install Name to #executable_path/../Frameworks/$(CONTENTS_FOLDER_PATH)/$(PRODUCT_NAME).
Set the Installation Directory of MyIBPlugin to #loader_path/../Frameworks/Resources.
(when built, the plug-in is placed in the Resources directory of the framework).
At this point, it should work both in Interface Builder and in IBCocoaSimulator.
Embedding in an application
Drag the IBPluginFramework.framework folder to the Linked Frameworks group of the application's project. Edit your application target: append to Frameworks Search Paths the path #loader_path/../Frameworks/MyIBPluginFramework/Resources.
You're now able to link against the framework and the plug-in, but the framework must be copied to the Frameworks directory of your application when building. Add a Copy Files phase to your target, and drag the framework into.
I cannot garantee success (I managed to make mine work, but might have forgotten to relate a step here), but you're given the big lines.
I thought that usually you put plugins in to the application specific folder found in the Library folder either at the root or user level, e.g.
/Library/Interface Builder 3.0/
On my system I have another folder under that called "Library", and under that called "User Objects" which is empty.
So I would try putting it in each of these folders in turn, restarting XCode and Interface Builder each time (just to be sure)
/Library/Interface Builder 3.0/
/Library/Interface Builder 3.0/Library
/Library/Interface Builder 3.0/Library/User Objects
Hope that helps.
I'm an experienced VS.NET user and trying to get up and running on Xcode 3.1.1.
Here's what I'm trying to accomplish:
I'd like a static library ("Lib") to have its own xcodeproj file. I'd an executable application ("App") that makes use of Lib to reference Lib's xcodeproj file so that changes to Lib cause App to relink. Ideally, I'd like to be able to edit Lib's source files inside App's Xcode workspace so I don't have to task around all the time to make changes.
I figured out from the online help that I can simply drag the static lib xcodeproj in to my app's project and it gets the reference. I see that once my static lib xcodeproj is in my app's project, I can simply drag it to the App's target and it understands that App depends on Lib. This seems like the right path, but things aren't quite working the way I'd like yet.
Here are my questions:
It seems that simply having App depend on Lib doesn't cause App to link with Lib. It seems that I have to explicitly drag libLib.a from the Lib folder into App's "Link Binary With Libraries" build stage. In VS.NET, simply specifying the project as a solution dependency adds it to the link line. I just want to make sure I'm not missing anything.
When I have App open in Xcode and I drag Lib.xcodeproj into it, I don't get any of Lib's source files there. I only get libLib.a under the "Lib.xcodeproj" folder. In VS.NET, I can edit Lib's source files right there and rebuild it, etc... but with this approach in Xcode, changes to Lib.cpp don't cause Lib to rebuild when I rebuild App. Ideally, I'd get all of Lib's source files and targets to show up when I drag Lib.xcodeproj into App. Is there any way of doing this?
Thanks in advance for any responses!
You're correct that making target A depend upon target B (whether within the same project or across projects) does not cause target A to link against target B. You need to specify them distinctly; this is because they're separate concepts, and you might have dependencies between targets that you don't want to link to each other — for example, a command-line tool that gets built by target C and is used as part of the build process for target A.
Also, you're correct that referencing project B from within project A will not let you see project B's source code in project A's window. That's because Xcode does not have the same "workspace" model that Visual Studio and Eclipse do; you above alluded to the existence of "a workspace containing project A" but Xcode doesn't really have any such thing, just a window representing project A.
Open the App project. Right-click on the App target and choose "Get Info." Then go to the "General Tab" and find "Direct Dependencies." Click the ( + ) (plus sign) button to add a direct dependency. The Lib.xcodeproj should appear among a list of possibilities for you. Choose the Lib target from that list.
That should accomplish that the Lib project must build (or rebuild) when you build the App target.
(Editing my own post now. I realize I said nothing about point number 2 in the question. I am actually still thinking about number 2. I am not sure if that is possible or not.)
I'm also novice to Xcode 3.1, just played with mentioned by you issues and found that there is no problem regarding to your second question. Whatever application you use to edit the dependence library source code, your main project will rebuild the dependence target. I checked it by:
edited the source file, of the library your app depend on, by notepad application.
Selected dependence library project reference, mouse right-click, and select 'Open With Finder', then selected wanted source file and edited it.
Everything working well.
I am also a fairly new user of Xcode. Most of what I know I learned from an Xcode book by James Bucanek (ISBN 047175479x). It is an older book that was written for/with Xcode 2.2, but I find that pretty much all of it still applies for me today, and I currently use Xcode 3.1
You can probably find a cheap used copy if you are interested.