Running OSX Bundle via Open - macos

I'm trying to make an OSX bundle using CMake/CPack on OSX that involves OpenCV and Qt (although I don't think those dependencies matter at this point). Everything compiles and the bundle is created fine, and I have a script that modifies the necessary library paths such the executable I'm making works if I run it from the Terminal within the bundle. The problem I'm having is if I try to run the MyApp.app file via the open command or by simply double clicking the app it gives me the error:
LSOpenURLsWithRole() failed with error -10810 for the file /Applications/
I've seen other solutions to other LSOpenURLsWithRole() errors involving modifying permissions, but that hasn't helped me. Also, this error code is an "unknown error" so I'm not sure how to proceed.

The solution for this ended up being that the libcocoa.dylib library was not finding the requisite libraries. See Building OSX App Bundle for a thorough answer on the subject. otool -L is your best friend.

Related

Xcode 11.2.1 - Command CodeSign failed with a nonzero exit code

I'm working on a SFML app for macOS with the latest Xcode version.
I got a "Command CodeSign failed with a nonzero exit code" error when it tries to sign the SFML frameworks. I added these under "Link Binary with Libraries" and "Copy Files" in Target, under Build Phases. Before, I was working with my local frameworks under /Library/Frameworks, and it was working very well.
Now I need to create an archive .app.
I've tried a lot of things seen on other posts here (like lock and unlock my keychains), but nothing worked. Still got that error.
My SFML Frameworks in "Link Binary with Libraries"
/Users/lounesksouri/Library/Developer/Xcode/DerivedData/Squadro-gqwjbvsooypqaifxxyzhdrahkdpo/Build/Intermediates.noindex/ArchiveIntermediates/Squadro/InstallationBuildProductsLocation/Applications/Squadro.app/Contents/Frameworks/sfml-system.framework/Versions/A: bundle format unrecognized, invalid, or unsuitable
Command CodeSign failed with a nonzero exit code
Ok, I solved my problem, after long hours.
It's a lot more simple to use the script already present in Build Phases tab, generated if you use the SFML App Xcode template (see here the original script). I had tried it at first, but it didn't work so I let it down.
But, in this script, the first three lines are not the good ones, for a normal SFML installation on macOS. We need to modify these lines with the good paths to the Frameworks and lib folders, as follows :
SFML_DEPENDENCIES_INSTALL_PREFIX="/Library/Frameworks"
CMAKE_INSTALL_FRAMEWORK_PREFIX="/Library/Frameworks"
CMAKE_INSTALL_LIB_PREFIX="/usr/local/lib"
FRAMEWORKS_FULL_PATH="$BUILT_PRODUCTS_DIR/$FRAMEWORKS_FOLDER_PATH/"
Secondly, there is still the code signing problem : the archive will created but we will get an error if we start the .app. The solution to this problem is to check Disable Library Validation under Target/Signing & Capabilities to allow the application to load plug-ins or frameworks signed by other developers.
Finally, if we create the archive and launch the application, everything goes normally, as planned.
I faced this problem with the new update of Xcode. I was reading your discussion, and did some accidental modifications. I am definetely not an expert but what I did fixed the problem so I did not receive tgis error anymore. So I added the sfml libraries (5 libraries), whose paths are written in build settings -> framework swarch paths. And this adding automatically added them in Embedded Frameworks under the Build phases section. What I did is unchecking the checkboxes of all 5 libraries "Code sign On copy". Thank you guys for giving me the path for "solving" the problem :))))
For the Code-signing issue:
Open a Terminal,
Go to the Framework folder (cd /Library/Frameworks) and sing them.
choose your identity
security find-identity -vp codesigning
sign them Frameworks!
codesign -s AD90FAFAFAFAFAFAFAF-YOURHASH-9D6 ogg.framework
codesign ... all the others
run and enjoy!

macdeployqt - "file not found" - missing qml file from qrc

I am trying to deploy an app using Qt (version 5.6.1) for OS X (10.11.5) with macdeployqt tool. Just after running qmake and make the app seems to work fine. However, when I try to use macdeployqt I am experiencing some errors. The qml files become nonexistent, and I get following result:
QQmlApplicationEngine failed to load component
qrc:/qml/main.qml:-1 File not found
I've tried to run macdeployqt from its directory (as some people on the web suggested) and even tried some funky build of this tool provided by third party... I am aware of macqtdeploy qmldir option (it didn't change anything). Does anybody know what exactly macdeployqt is doing to those resources? Why they are missing?

Unable to run Swift code using Command Line Tools

I downloaded Xcode CLT from developer.apple.com/downloads and then installed the package.
Wanting to try my hands at Swift, I attempted to write a simple "hello, world" program, but, things seemed to be "wrong" from the first moment I started it. Look at the following screen output:
$ xcrun swift
Welcome to Swift! Type :help for assistance.
dyld: Library not loaded: #rpath/libswiftCore.dylib
Referenced from: /Library/Developer/CommandLineTools/Library/PrivateFrameworks/LLDB.framework/Versions/A/Resources/repl_swift
Reason: image not found
1> s="hello, world"
Error in auto-import:
failed to get module 'Swift' from AST context
1> ^D
I am especially concerned with the "dyld" line which is about line # 3 in that output.
I searched around on the web and found that this is caused by some certificate mismatch issues. But, I have neither requested any certificates from Apple, nor issued any certificates to anyone. I just want to try out Swift without downloading the entire XCode.
So, the questions are:
why am I getting the "dyld: Library not loaded:..." error?
how can i fix it?
how can I write, compile and run simple Swift code on the command line before downloading the entire XCode?
Your help is greatly appreciated. Anxiously waiting for your reply.
Edit:
Here's how I installed the tools: I downloaded the tools from the developer.apple.com/downloads web site. I got a dmg file, which I clicked. It contained a package file. When I clicked that, it brought up a nice popup that said something to the effect "installing". I went through all the dialogs it threw at me, selecting all the default values. After a few moments, it said "installed".
I then opened emacs, wrote 10 lines of c, compiled and ran it. worked! So, I got on the web, located the most elementary swift program I could find, copied it and attempted to run it ... and boom ... I got that error. So I started the swift interpreter and typed code into it. Nope! That didn't work either!
So, given all that ... I feel I did my best to install the tools, but, please let me know if I have missed any step that could have caused the CLT to install partially and not completely.
failed to get module 'Swift' from AST context
Use the xcode-select command-line tool:
sudo xcode-select --switch /Applications/Xcode.app
or if you are using Xcode-beta then use this:
sudo xcode-select --switch /Applications/Xcode-beta.app
From the xcode-select manual:
After setting a developer directory, all of the xcode-select provided developer tool shims ... will automatically invoke
the version of the tool inside the selected developer directory.
For more info:
man xcode-select
cd /Library/Developer/CommandLineTools/Library/PrivateFrameworks/LLDB.framework/Versions/A/Resources
and then
sudo install_name_tool -rpath #executable_path/../../../../../Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx /Library/Developer/CommandLineTools/usr/lib/swift/macosx repl_swift
Will get rid of the first part of the error. I can't figure out the 2nd part yet. (Error in auto-import). Anyone have any ideas based on the first part of the solution?

Deploying Qt Frameworks with Mac app and usage of otool

I have a problem deploying Qt frameworks with my Mac app, and I hope some will have a clue why I get this error, when I run the app on clean Mac, i.e. not a developer Mac.
OS: 10.7 .2 and using XCode
Error msg:
Library not loaded: #loader_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
Referenced from:/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/../Frameworks/../Frameworks/QtXml.framework/Versions/4/QtXml
Clearly something is wrong since the QtXml is referenced from /../Frameworks/../Frameworks, which doesn’t exists.
This is the set up: I have a dylib that uses QtCore and QtXml (not by my choosing, but for now I need those two frameworks), the dylib is used in a NSBundle, which is loaded by the main app, the bundle is located in the resource folder. The dylib is moved by Copy Files Build Phase to the folder Contents/Frameworks and with otool the install_name is set to (as stated by http://doc.qt.digia.com/4.3/deployment-mac.html):
#loader_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
#loader_path/../Frameworks/QtXml.framework/Versions/4/QtXml
then the Qt frameworks are moved to Contents/Frameworks and the install_name of the is set to:
#executable_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
and for the QtXml
#executable_path/../Frameworks/QtXml.framework/Versions/4/QtXml
with reference to QtCore:
#executable_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
Now when I run the app on the developer mac it clearly works since Qt is installed, but when moved to a clean mac I get the error msg, readable in the Console app.
I’ve tried to change the executable_path to loader_path, but this didn’t work.
I have no idea what I’m doing wrong or why it won't for, and have not been able to find anything on Google, of course I could be looking at the wrong places. Any ideas how to fix this problem?
This is the entire error message:
MainApp: Error Domain=NSCocoaErrorDomain Code=3587 "The bundle
“Library” couldn’t be loaded because it is damaged or missing
necessary resources."
(dlopen_preflight(/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/
Contents/MacOS/Library): Library not loaded:
#loader_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
Referenced from: /Users/ someUser /Downloads/
MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/../Frameworks/../Frameworks/QtXml.framework/Versions/4/QtXml
Reason: image not found) UserInfo=0x107c5d5d0
{NSLocalizedFailureReason=The bundle is damaged or missing necessary
resources., NSLocalizedRecoverySuggestion=Try reinstalling the
bundle.,
NSFilePath=/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/Library,
NSDebugDescription=dlopen_preflight(/Users/someUser
/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/Library):
Library not loaded:
#loader_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
Referenced from:
/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/../Frameworks/../Frameworks/QtXml.framework/Versions/4/QtXml
Reason: image not found,
NSBundlePath=/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle,
NSLocalizedDescription=The bundle “Library” couldn’t be loaded because
it is damaged or missing necessary resources.}
On the development mac everything works because the Qt libraries are installed. On any mac you ship the app to, though, this likely won't be the case. The Qt suite comes with a tool called macdeployqt to fix this. So in a terminal, after you've compiled your application, do something like:
# cd my-cool-app-Desktop
# macdeployqt my-cool-app.app
Note that it can also be used to create a .dmg file for shipping everything together:
# cd my-cool-app-Desktop
# macdeployqt my-cool-app.app -dmg
Once you've done that, the .app directory or .dmg file can be given to someone else without Qt installed to use and run as they normally would.
The one caveat is that the next time you try to run it on your developer machine, it may complain about multiple shared libraries installed. So once you've copied it else where in order to distribute it, remove the entire .app directory and let qtcreator (or whatever) rebuild it.
UPDATE
As stated compiling QT to static libs is the way to go. With the release of Mavericks (10.9) we need to codesign frameworks as well (http://furbo.org/2013/10/17/code-signing-and-mavericks/), and with QT4.8.5 there are some issues (https://bugreports.qt-project.org/browse/QTBUG-32896). Even with suggested fixes I still had some issues when running the app on a clean machine. Therefore, I ended up with compiling Qt5.2 to staticlibs, link them in the app, and codesign them.
OLD
Problem sovled, I moved the Qt-frameworks into the app bundle in Contents/Frameworks and with otool set the path to #executable_path/../Frameworks, i.e. moved it out of my library bundle. Yes the solution is simple, but I'm still not sure why the library executable couldn't find the frameworks when using #loader_path.
The best solution would probably be to use a static library and not wrap it in a bundle...you learn everyday ;)

Command libtool failed with exit code 1

I've created a static library C++ project but when I compile I get the following error:
XCode 4.1 (Lion) doesn't show me any more information what's going wrong. I'm using clang.
How can I find out what went wrong?
I have read elsewhere, and confirmed myself, that the problem is that Xcode is suppressing the output from stdout.
As a work around, in Xcode, flip open the display of the commands being executed and copy and paste them into a Terminal session and run lib tool from there.

Resources