Closed michaelgwelch closed 9 years ago
This is more of a general question so I asked at Stackoverflow as well. http://stackoverflow.com/questions/26691653/how-do-i-link-to-a-3rd-party-swift-framework (I can't even figure out how to consume my own frameworks.)
First, can I get you to run a clean (⌘+⇧+⌥+K
). Then rebuild
Sure. I did the following. Pulled the latest code as of just a few minutes ago. Followed your key combination to clean build folders.
I then rebuilt. I then paid closer attention to the "schemas" available. I'm referring to the list of "targets" in the menubar just to the right of the run and stop buttons. I currently see 8 listed.
Two of the entries are named "swiftz (swiftz project)". I can successfully build and test these. Two of the entries are named "swiftz_core (swiftz_core project)". I can successfully build but not test these. Two of the entries are named "swiftz_core_ios (swiftz_core project)". These run and test successfully. Two of the entries are named "swiftz_ios (swiftz_project)". These build. There apparently are no tests.
It's weird you would say that. I've got four buildable schemes and all of them test just fine. In fact, even Travis can see them and is giving us the all clear. What happens when you add a copy files phase to the test schemes, set the path to "frameworks", and add the appropriate swiftz_core?
Ok. Let me address your first comment first. Obviously something is wrong with my working directory.
Running git status
shows no local changes but I'm going to do a git clean -fxd
and/or clone a fresh copy of the repository.
Well, git clean
made a change. Now I see 5 schemes. 4 of them look like yellow lunch boxes, but 1 is a white lego (swiftz_iosTests somehow is listed separate from swiftz_ios).
Ok, going to pull a fresh clone. (I'm using XCode Version 6.1 (6A1052d) by the way).
Success! I cloned a fresh copy. Still had issues running the tests for swiftz_core. Said it couldn't load the swiftz_coreTests bundle at /Users/mgwelch/Library/Developer/Xcode/DerivedData/swiftz-dfchxmsrsusopsgocnqvrawwpzyp/Build/Products/Debug/swiftz_coreTests.xctest/Contents/MacOS/
I went to that location. Deleted the binary that was there. Rebuilt. And then the tests passed.
This doesn't make any sense to me since but I'm now building and successfully running all tests.
Now I just have the final question of which of these frameworks do I need and how do I add them to another workspace and/or project?
In a .Net language using Visual Studio, I'd just right click the project and say "Add Reference".
In C/C++ (which I've not used a ton but have used them) I'd add the library to a linker setting and make sure the library was in my link path.
I really have no clue what to do for frameworks. Apple makes it look like it's as simple as drag/drop or click a + key and add the framework. However, the linker never finds the library I've added. Perhaps I need to make sure the library is copied to the right location when I drag/drop and then make sure some link path is up to date?
If you want to use it in an Application, you'll need to do the following:
Just a quick question about dragging the project into the file tree. It looks like you did this in the swiftz project as well, as swiftz_core is embedded under the swiftz project. And the whole swiftz_core project is shown embedded under swiftz.You can expand it and see all the files.
When I drag swiftz into my project, I just get an icon for the project, but none of the files under the project are there. I can't expand the project and navigate. Is this a problem? Can I ignore that?
Did you drag in the workspace or the xcodeproj? The workspace is where we keep both projects as a convenience, but each individual xcodeproj is what you should probably be using here.
If you did, it's because Xcode will not allow you to have the same project open in more than one window. Submodules included. sigh . Close both windows, then reopen your project.
I dragged the xcodeproj. I tried it from Finder. I tried it from one XCode window to another.
(This is not how you consume objective-c frameworks right? This is just a "stop-gap" solution until Apple solidifies their swift runtime and adds true support for reusing binary form of swift frameworks? Because this seems to not work too well.)
Ok, you do not want to have swiftz open in XCode when you do the drag/drop. That was my problem. I'll move onto the next step now. (Fortunately, I eventually got an error telling me that it couldn't open up swiftz project because it was open already.)
Finally, in the copy file phase, the default destination is Resources. Is that correct or should I select Frameworks.
Frameworks, please. The dyld will thank me later.
Well, thanks for all your help. I'm getting closer but I'm getting a dyld error anyway.
dyld: Library not loaded: @rpath/libswiftAppKit.dylib
Referenced from: /Users/mgwelch/Library/Developer/Xcode/DerivedData/playwithswifts-attigdsrimbroebdxizhevdsxpls/Build/Products/Debug/swiftz_core.framework/Versions/A/swiftz_core
Reason: image not found
Of course, when I look at that location the framework is there. I'm less than enthused with the amount of polish Apple has put into XCode to support Swift. This doesn't seem like a released version of a product, yet.
Not sure why it's looking there anyway. Shouldn't it be looking wherever we copied them to in the copy files phase?
Go under your project's "Build Settings" tab, search for "Embedded content contains"
You should see "Embedded content contains Swift Code" No Change it to Yes
I believe up above when you told me how to add to my project, you skipped a step. I need to add the appropriate framework to the Link phase correct?
I've done that. Still dyld error.
Now, I have an extra bonus problem.Now whenever I have swiftz_core framework in the copy phase I get the following build error (which wasn't happening 10 minutes ago).
Unable to run command 'PBXCp swiftz_core.framework' - this target might include its own product.
Well, I truly appreciate all of your help. I'm going to call it a night.
I sure wish Apple had more support for this stuff. This doesn't seem "ready for prime time".
Okay. I've come at this fresh with a sample project of my own. Here's the revised steps I'm considering submitting to a new README:
swiftz.xcodeproj
into your application's Xcode project or workspace.+
at the top left and add one.--deep
is set.With these instructions I can get any number of applications up and running from Xcode's default templates. If you'd like I can send you a working project of mine to see if it isn't just on your end.
Ok, maybe I need to try reinstalling XCode. Still get a linker error, but I looked more closely at it. I thought it was saying it couldn't find your framework. But it's a swift runtime framework it can't find:
dyld: Library not loaded: @rpath/libswiftAppKit.dylib
Something like this question might be related: http://stackoverflow.com/questions/24972359/unable-to-load-swift-runtime-library-image-not-found
I'm going to look into the settings mentioned there.
I can link it to a Cocoa App (really wanted a command line app) but decided to play with that.
I ran all the default tests in the default app template. They run.
Then I add the following line to a test:
var x = List<Int>.Nil;
or
var x:List<Int> = [1,2,3]
and set a breakpoint. The tests break at that line. But if I try to step into them or step over, or just run the tests without breakpoints - the tests just hang.
This is actually the same result I got when I tried creating my own recursive enum implementation of List a few days back. It really seems like my installation of XCode is sick. I think I'll bite the bullet, uninstall, clean the best I can, and reinstall.
Thanks for all of your help.
You can't bundle frameworks and dylibs with command line tools. You need a static library for that, and our hands are tied on that front by the language.
I give up. Still can't get it to work. I could try to troubleshoot by figure out where it's looking for rpath but I'm not familiar enough with the build tools to even know how to get it to spit out what it thinks @rpath is.
I reinstalled XCode, created a default projected, made all the changes you said and still dylib can't find the swift library listed above. Feel free to close this issue, I think you did about all you can on this one.
I'll just play around with swiftz in your test projects or try it from a playground.
Wait, I just re-read what you typed. You can't bundle frameworks and dylibs with command line projects?
Now that would be a useful thing for XCode to tell you upon adding a framework to your link phase when you are in a command line project.
Ok, then I guess I'm just left to figure out why whenever I write (or you write) a recursive enum list List
We may be spinning forever in the ArrayLiteralConvertible constructor. Gimme a sec to check.
Welp, that was the weirdest debugging session ever. You're absolutely right about it being the runtime that hangs. I'm filing a radar I have filed a radar for that problem (rdar://18903483), in the meantime #120 should do right by you.
Cool! I just opened up a stack overflow question on this and was going to try to debug. I would have never guessed to box the first parameter of Cons. Wow!
Thanks for filing the radar.
I assume this broke "recently" as I'm sure this code worked when it was first written?
What tool would you use to debug this? Instruments?
I wasn't around when it was first written, but that sounds about right. Recursive enums were always trouble, but I've never seen this before.
@CodaFi I think this issue can be closed now. All of my issues were resolved or explained.
Thanks
Alright, then.
If you have anymore questions, don't hesitate to open another issue.
Could you update the readme with more detailed info on how to consume a framework. I know it's not an issue with your code (it's my issue as an XCode beginner). I just can't ever figure out how to consume frameworks. Apple makes it seem as if you just drag and drop (which appears to work until you actually try to build and the linker yells at you)
I'm trying to follow your instructions on your readme.
The way things stand I get a linker error: swiftz framework cannot be found.
Thanks for any pointers to documentation that will get me on the right track. Would really love to be able to play around with Swiftz.
Test Output
2014-11-01 11:14:37.419 xctest[3562:119069] The test bundle at /Users/mgwelch/Library/Developer/Xcode/DerivedData/swiftz-dfchxmsrsusopsgocnqvrawwpzyp/Build/Products/Debug/swiftz_coreTests.xctest could not be loaded because an unanticipated error occurred. 2014-11-01 11:14:37.419 xctest[3562:119069] Detailed error information: Error Domain=NSCocoaErrorDomain Code=3587 "The bundle “swiftz_coreTests” couldn’t be loaded because it is damaged or missing necessary resources." (dlopen_preflight(/Users/mgwelch/Library/Developer/Xcode/DerivedData/swiftz-dfchxmsrsusopsgocnqvrawwpzyp/Build/Products/Debug/swiftz_coreTests.xctest/Contents/MacOS/swiftz_coreTests): Library not loaded: @rpath/libswiftAppKit.dylib Referenced from: /Users/mgwelch/Library/Developer/Xcode/DerivedData/swiftz-dfchxmsrsusopsgocnqvrawwpzyp/Build/Products/Debug/swiftz_core.framework/Versions/A/swiftz_core Reason: image not found) UserInfo=0x1005002a0 {NSLocalizedFailureReason=The bundle is damaged or missing necessary resources., NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSFilePath=/Users/mgwelch/Library/Developer/Xcode/DerivedData/swiftz-dfchxmsrsusopsgocnqvrawwpzyp/Build/Products/Debug/swiftz_coreTests.xctest/Contents/MacOS/swiftz_coreTests, NSDebugDescription=dlopen_preflight(/Users/mgwelch/Library/Developer/Xcode/DerivedData/swiftz-dfchxmsrsusopsgocnqvrawwpzyp/Build/Products/Debug/swiftz_coreTests.xctest/Contents/MacOS/swiftz_coreTests): Library not loaded: @rpath/libswiftAppKit.dylib Referenced from: /Users/mgwelch/Library/Developer/Xcode/DerivedData/swiftz-dfchxmsrsusopsgocnqvrawwpzyp/Build/Products/Debug/swiftz_core.framework/Versions/A/swiftz_core Reason: image not found, NSBundlePath=/Users/mgwelch/Library/Developer/Xcode/DerivedData/swiftz-dfchxmsrsusopsgocnqvrawwpzyp/Build/Products/Debug/swiftz_coreTests.xctest, NSLocalizedDescription=The bundle “swiftz_coreTests” couldn’t be loaded because it is damaged or missing necessary resources.} 2014-11-01 11:14:37.420 xctest[3562:119069] Usage: xctest [-XCTest Self | All | None | ] 2014-11-01 11:14:37.420 xctest[3562:119069] Couldn't posix_spawn: error 8