Getting "Library not loaded: #rpath/libswiftSwiftOnoneSupport.dylib" error - xcode

The problem occurred when I adding Nimble as a git submodule. I've fired an issue on Quick/Nimble, but the problem appears to be not likely a Nimble issue, it maybe rather an Xcode issue, thus I'm asking here.
I set up a simple project according to Nimble installation guid and it's on github now. Basically I created an xcworkspace and an xcodeproj (added to the workspace). Nimble is added as git submodule and subproject to the workspace. Then I added Nimble.framework to my test targets Build Phases and wrote some simple test code to see if Nimble was running.
And when I run the test, Xcode gave this error message:
2017-02-20 23:41:29.482 xctest[52165:616190] The bundle “MainProjTests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
2017-02-20 23:41:29.483 xctest[52165:616190] (dlopen_preflight(/Users/nandiin/Library/Developer/Xcode/DerivedData/NimbleIssue-fkhppktoktwpjodtarmzrjobszwv/Build/Products/Debug-iphonesimulator/MainProjTests.xctest/MainProjTests): Library not loaded: #rpath/libswiftSwiftOnoneSupport.dylib
Referenced from: /Users/nandiin/Library/Developer/Xcode/DerivedData/NimbleIssue-fkhppktoktwpjodtarmzrjobszwv/Build/Products/Debug-iphonesimulator/Nimble.framework/Nimble
Reason: image not found)
Program ended with exit code: 82
I've tried some solution I found for similar problems and they didn't work:
setting Embed Asset Packs In Product Bundle to YES (tried for both main target and test target)
setting Always Embed Swift Standard Libraries to YES (tried for both main target and test target)

The issue is the run path for the dynamic library:
libswiftSwiftOnoneSupport.dylib
If this is not included in the app bundle after building your app you'll want to add it by including it in the Copy Files Build Phase. Another possible problem could be that it's run path is not correctly set ( which you'll need to set if not already ), or fix the rpath with install_name_tool.
↳ Run-Path Dependent Libraries

Related

XCode - creating archive fails with error «…-Prefix.pch» not found

I have a workspace with multiple targets.
Each target has its own prefix.pch file.
Prefix-Header is entered in Build Settings and Precompile Prefix Header is set to YES.
The app compiles and runs fine when I run it on my device.
There are no errors when I just build the app.
But when I try to archive it, I get a compile error saying:
No such file or directory: '/Users/me/Library/Developer/Xcode/DerivedData/myApp-dcmvkatguqcxgjfyrqcunbsfuxcd/Build/Intermediates.noindex/ArchiveIntermediates/myAppTarget/PrecompiledHeaders/SharedPrecompiledHeaders/13524936819627194222/myAppTarget-Prefix.pch'
And indeed, when I open this folder on my hd, I can't see the pch-file. There are, however, similar files there:
myAppTarget-Prefix.pch.d
myAppTarget-Prefix.pch.dia
myAppTarget-Prefix.pch.gch
I tried everything I found on SO and elsewhere, but nothing helped.
I have Cocoapods installed and use them in this project, but I don't think that error is related to that (they seem to compile fine).
XCode 12.4
Seems like I figured it out.
The culprit was a totally unrelated build-setting.
In Other C Flags my settings differed in debug and release.
I had $(inherited) in both of them, but in the release setting I additionally had -isystem - which apparently is already included in $(inherited). That caused a multitude of errors that ended with the prefix.pch not being copied...

iOS build: command ld failed with a nozero exit code

For a react-native project, I got the following error during Xcode build:
clang: error: no such file or directory: '/Users/user172615/Library/Developer/Xcode/DerivedData/xxx/Build/Products/Debug-appletvsimulator/libBVLinearGradient.a'
Command Ld failed with a nonzero exit code
This happened after adding react-native-linear-gradient, and following the instructions in https://github.com/react-native-community/react-native-linear-gradient (manual installation for iOS).
As specified in https://github.com/react-native-community/react-native-linear-gradient#manually, libBVLinearGradient.a is included in Build Phases -> Link Binary With Libraries for the target myProject
libBVLinearGradient.a is also included in General -> Frameworks, Libraries and embedded content.
I tried deleting DerivedData, and rebuilding. Didn't help.
Since the error indicates Debug-appletvsimulator, I included libBVLinearGradient.a in Build Phases -> Link Binary With Libraries for the target myProject-tvOS
When this didn't help, I deleted the myProject-tvOS target. All didn't help.
I am using Xcode 11.3, react-native 0.59.9.
Any idea?
Instead of downloading it, do this instead.
Click on clone existing project
Then copy this link
https://github.com/react-native-community/react-native-linear-gradient
And paste the link here
Then it will download the project.
If the problem still happens, then create a new project, copy and paste everything.

OSX App crashing on load when ParseOSX framework with Dyld Error

I have an OSX app and I have added the ParseOSX sdk. I have followed all the instructions on the quick start page (https://www.parse.com/apps/quickstart#parse_data/desktop/osx/existing)
The app is running fine in Xcode (Version 5.1.1 (5B1008)) but when I archive and create a package and install this. I get the following Dyld error;
Dyld Error Message:
Library not loaded: #executable_path/../Frameworks/ParseOSX.framework/ParseOSX
Referenced from: /Applications/MyApp.app/Contents/MacOS/MyApp
Reason: image not found
It goes on and lists the Binary Images loaded.
Searching the web I found reference to adding a copy files build phase and adding the parse framework to that with the destination set to Products directory.
So it appears there is a dynamic lib not being installed somewhere.
UPDATE:
I just cleaned the build folder and now the app will not even run under Xcode. I get:
dyld: Library not loaded: #executable_path/../Frameworks/ParseOSX.framework/ParseOSX
Referenced from: /Users/Ants/Library/Developer/Xcode/DerivedData/MyApp-hjrbgyhzpwnxhiaskxpojqyqxnvh/Build/Products/Debug/Actual.app/Contents/MacOS/MyApp
Reason: image not found
UPDATE 2:
It turns out when you are in the quick start page. If you chose the new app option you get a Xcode project. This compiles. Going through it I can see that there is is a Copy Files step that copies the ParseOSX.framework into the Frameworks destination. Tried this is my app and I now get a signing error
/Users/Ants/Library/Developer/Xcode/DerivedData/MyApp-hjrbgyhzpwnxhiaskxpojqyqxnvh/Build/Products/Debug/MyApp.app: code object is not signed at all
In subcomponent: /Users/Ants/Library/Developer/Xcode/DerivedData/MyApp-hjrbgyhzpwnxhiaskxpojqyqxnvh/Build/Products/Debug/MyApp.app/Contents/Frameworks/ParseOSX.framework
I ran into the same problem with xcode 6.1. Fixed it by adding ParseOSX.framework to "Embedded Binaries" on the general tab of the Targets page.
Two things fixed this for me.
First I needed to add a copy files section to the build phases and copy the ParseOSX.framework into the Frameworks destination.
And second, I needed to add --deep to the "Other Code Signing Flags" in the Code Signing section of Build Settings. It now signs the frameworks being copied it seems.
I was updating an existing parse project to the newest SDK (1.12.0) using Xcode 7.2 and ran into the same problem.
The solution for me was to set Runpath Search Paths to #executable_path/../Frameworks.
I found this by comparing the Starter project from Parse to my project.

Install Fragaria framework

I was looking for a way to implement syntax highlighting on my cocoa app and I found the great Fragaria framework https://github.com/mugginsoft/Fragaria. Unfortunately I seem to be unable to install the framework in my app.
Here are the steps I follow:
Compile the framework from the source code target
Add the framework to the "Link Binary with Libraries" build phase of XCode 4
Drag the framework into "Copy Bundle Resources"of build phase
Unfortunately when I try to build my app I get this error:
dyld: Library not loaded:
#executable_path/../Frameworks/MGSFragaria.framework/Versions/A/MGSFragaria
Referenced from:
/Users/dedalus/Developer/DEGS/trunk/build/Debug/DEGS.app/Contents/MacOS/DEGS
Reason: image not found
Which step am I missing?
Don't add the framework product to the Copy Bundle Resources build phase. Instead, create a new Copy Files build phase, set its destination to the Frameworks directory and add the framework build product to this phase. The Copy Bundle Resources build phase copies the framework to the resources subdirectory (Contents/Resources on OS X), but the dynamic linker expects it to be in the frameworks subdirectory (Contents/Frameworks on OS X). The newly added Copy Files build phase will put it there.
BTW, the error you're seeing is a run-time error, not a compile-time error. So strictly speaking you get this error when running the app, not when building it.

Setting dylib paths as a XCode build step

I have a Cocoa application as XCode project that has several supplementary bits of functionality as dylib targets.
When XCode builds the project, it places all the build outputs in a single folder: The .app bundle and the dylib files. And when executed from the XCode debugger, the .app launches.
I can't however launch the application from finder.
How do I setup XCode to 'deploy' the app in a standalone state? I have found that I can use ld on the actual app binary to contain a relative path to the dylibs: #executable_path/../../mylib.dylib
Running a script after each build seems wrong: there must be some way (that Im totally missing) to do this easily from inside XCode - it must be a common issue surely?
It looks like that XCode supports having #executable_path, #loader_path and #rpath used in the Target Info > Build > Linking > Dynamic Library Install Name setting (LD_DYLIB_INSTALL_NAME) setting.
The help text says: "Sets an internal "install path" (LC_ID_DYLIB) in a dynamic library. Any clients linked against the library will record that path as the way dyld should locate this library"
This seems very promising, but usability is a problem if I need to link dylibs in multiple paths against a common library - the relative path is going to be different each time.
Running my testapp from finder, I get the following (relevant) error text
Dyld Error Message:
Library not loaded: #executable_path/../../util.dylib
Referenced from: /Volumes/data/Code/TestApp/build/Debug/TestApp.app/Contents/MacOS/TestApp
Reason: image not found
util.dylib is in /Volumes/data/Code/TestApp/build/Debug/ so I am confused :/
You should use a Copy Files build phase to copy the dylib to the app's bundle when building the app. You'll want to copy it to Frameworks. You can then set the install path to #executable_path/../Frameworks/mylib.dylib.

Resources