What is an App Bundle on Mac? - c++

I have a basic C++ applicatin build using g++ and -framework ...
when I run it, I get a :
Working in unbundled mode. You should build a .app wrapper for your Mac OS X applications.
(which is not std::couted by any of my application).
What causes this, and how can I get rid of it?
Thanks!

You need to create a folder structure and place the binary in a special location. For an example with explanation see this Qt page
Mac OS X handles most applications as "bundles". A bundle is a directory structure that groups related files together. Bundles are used for GUI applications, frameworks, and installer packages. These are presented to the user as one file in the Finder. When set up correctly, bundles make for easy deployment. All one needs to do is to archive the application using some preferred method. Users then open the archive and drag the application to wherever they please and are ready to go.
There is something written about this for wxWidgets too
MacOSX introduces a new way of putting together an application. Instead of adding a resource fork to the executable file, you can simply create a special directory (folder). This is the preferred method for OSX.

Related

Xcode can't find files that exist (using c++ fopen)

I've been running into this strange problem lately where in my Cocoa app project in Xcode I get the error that the file was not found when using "fopen" (errno 2), called from a C++ file. I made sure to copy these files into the project's directory, then I dragged them from the Finder directory into the Xcode project tree. And finally, in the scheme's options I checked "use custom directory" and entered the directory where I have the project and all the files. The programme builds fine, but during runtime I get a BAD ACCESS error and I can see that my FILE* variable is still NULL. The command that throws the exception is actually "fread" two lines later, but it's only because "fopen" didn't do its job.
This whole setup has worked fine before in pure C++ projects. But this is different because it started as a Cocoa app in Objective-C (because I intended to use C++ for the programme's main logic). At some point I also had to change the extensions of all the ".m" files to ".mm" or the compiler wouldn't even find the C++ standard library! (but this is probably beside the point)
So the question is.. what else do I need to check in order to have the programme find the files I'm trying to open?
NOTE: the backbone of the project is written in C++, and I'm only using Cocoa in order to be able to dram images on the screen, so if anyone has a better approach to including graphics in a C++ project I'm all ears.
Thanks for reading
EDIT: I'm using Xcode 12.4 and Catalina 10.15.7
Cocoa apps do not work with files the same way as command-line C++ apps. Cocoa apps create an app bundle, which is where the files you want to read should be. If you have files you want to read in a Cocoa app, add them to the project. When you add the files to the project, they will get copied to the app bundle. Make sure they are in the app target's Copy Bundle Resources build phase.
Use the methods in the Bundle class to locate the files instead of fopen. The following Swift code locates a file named "MyFile.txt" in the main app bundle:
let mainBundle = Bundle.main
let fileURL = mainBundle.url(forResource: "MyFile", withExtension: "txt")

C++ qt application compilation in one file

I have written windows gui application using qt and i want to deploy it.Now when i place .exe to other PC it shows error which says that qt5core.dll and etc required.I can install this dll,but is it possible to run exe app with qt without qt's dll as one file?So i can for example give .exe to my friend and he can instantly run it without installing .dll?
Basically, if you want a single exe file, you probably mean static linking.
The legal commercial version makes it possible or if I am not wrong, you will have to build a static qt version.
In the latter case, you will have to provide the source code of your application.
I do this sometimes, but you'll have to be careful with the license requirements: if you go with GPL, it should be OK, if you choose LGPL, it may be a bit less simple. No idea about the commercial version.
What you must do is building Qt statically, and then use that Qt build to build your application. I had a good experience with mxe. MXE builds an entire crossbuild environment and allows you to build your big Qt exe statically. I used it on Mac OS and Linux to build static executables for Windows, but you can probably run it on WSL. It takes a bit to compile, but it is simple to use. Please note that it cannot be used if your app needs QtWebEngine as it won't build with mingw.
Another simpler option is to create an installer. The Qt installer framework is simple to use. If you include the VS runtime, you end up with a single exe to distribute (the installer).
You always need to include the libraries you use (including your compilers runtime libraries in fact) when you deploy your executable - otherwise how would your application be able to use the code in those libraries? You may be able to statically link some/most things, but rarely everything. Look into how to create an installer / package for your application, so you can bundle up everything as one convenient file.
You can buid you app using QT Static (a large .exe file, no external dependencies)
If you are using LGPL Qt, you must read this:
https://www.qt.io/faq/3.7.-what-are-my-obligations-when-using-qt-under-the-lgpl
Yo can use Qt and static linking, but "The user of your application has to be able to re-link your application against a different or modified version of the Qt library"
You can use an application template like this, very useful for LGPL Qt:
https://marketplace.qt.io/products/qt-lgpl-app-template

Install Qt without admin rights

I'd like to download Qt. I tried to download it from Qt's website but this gives me an exe file and since I've got a limited account when I try to run it it asks for an admin password. I've searched the web for a way for a limited account to install Qt but I haven't found anything. Could someone please help me find a solution?
In case it matters, I'm using Code::Blocks and Windows 7.
You could download the free software source code and compile and build it on your machine (that takes about a whole night, or maybe more). Don't forget to configure the build appropriately (I don't know Windows, but on Linux I'll suggest explicitly setting the -prefix to some writable directory ...). Before starting, ask explicitly your boss for permission (if you violate your company policies, you can be fired at once), and ask for guidance from someone knowing your operating system better than you do. You might need to change your PATH too.
Alternatively, ask permission to install and use a Linux distribution.
PS. Be sure to get permission to do something (even if technically you can do it alone).
You can download this ZIP file with Qt. All you have to do is unzip the ZIP file (which will take time) and place the files it contains in the right folder, nothing that requires administrator privileges. I recommend you put the contents of the ZIP file in C:\Qt, otherwise it might not work correctly (if this folder doesn't already exist, you can create it without administrator privileges and if it does exist, Qt is probably already installed on your computer in which case you don't need to do anything). I've also posted Qt's license agreement as it is in the installer program here since Qt wants you to read it before you use Qt.
Furthermore, I recommend using Qt Creator to make your Qt projects instead of Code::Blocks, because it's difficult to get Qt5 to work with Code::Blocks and Qt5 is the version of Qt used on both this website and Qt's installer (see this question) (if you find a way to get Qt5 to work with Code::Blocks, all the better, maybe you could even answer the question for which I posted a link). Qt Creator is included in the ZIP files on my website and to use Qt with Qt creator, all you have to do is include the right header files, no linking is needed. The path of Qt Creator is in the table on the bottom of the website.
You can download an archived distribution of MSYS2. After you extract and run it, you can use its packet manager to download numerous packages, including Qt. The only downside is you will have to settle for the version it provides, which is a little old, currently 5.5.1. You can install by typing:
pacman -S mingw-w64-i686-qt5 // for 32bit build or
pacman -S mingw-w64-x86_64-qt5 // for 64bit
This will install Qt and all dependencies automatically. Make sure your antivirus is not running in the final stage, because it can mess with the binary patcher that patches Qt to run from its current installation folder (because advanced software like Qt apparently cannot work without hard-coded paths).
You can even get a static build of Qt, which is quite useful, just add a -static to the package name.
Just in case you were wondering - MSYS2 is a build environment, it can come quite in handy, for getting ready to use libraries, or for building libraries which require a build environment. You can build Qt without it, however, it is a very slow process that may fail, and even though it is not complex to do, I would not recommend it as a first option.
If you still decide to build it from source, there is a detailed guide which will get you through the process.

Qt Application : How to create standalone executable file for Windows (& Mac) from Mac?

I developed a Qt application in MacBook (El-Capitan 10.11.2) and it is ready now to be released.
What i want now, is to create the standalone executable file for both Mac and Windows OS.
But I don't know how !
I found this link but I am unable to follow it is guidance, it looks different from what my system is showing me.
If you have any idea, please help me.
Thank you
Well, to compile an application for windows, you will need a windows machine (or at least a virtual machine). You can't compile for windows on mac.
Regarding the "standalone": The easy way is to deploy your application together with all the required dlls/frameworks and ship them as one "package". To to this, there are the tools windeployqt and macdeployqt. However, those will not be "single file" applications, but rather a collection of files.
If you want to have one single file, you will have to build Qt statically! You can to this, but you will have to do it on your own. And if you do, please notice that the LGPL-license (the one for the free version of Qt) requires you to make the source-code of your program public! That's not the case if you just link to the dynamic libraries.
EDIT:
Deployment
Deployment can be really hard, because you have to do it differently for each platform. Most times you will have 3 steps
Dependency resolving: In this step, you collect all the exectuables/lirabries/translations/... your application requires and collect them somewhere they can find each other. For windows and mac, this can be done using the tools I mentioned above.
Installation: Here you will have to create some kind of "installer". The easiest way is to create a zip-file that contains everyhing you need. But if you want to have a "nice" installation, you will have to create proper "installers" for each platform. (One of many possibilities is the Qt Installer Framework. Best thing about it: It's cross platform.)
Distribution: Distribution is how to get your program to the user. On Mac, you will have the App-Store, for windows you don't. Best way is to provide the download on a website created for this (like sourceforge, github, ...)
I can help you with the first step, but for the second step you will have to research the possibilities and decide for a way to do it.
Dependencies
Resolving the dependencies can be done by either building Qt statically (this way you will have only one single file, but gain additional work because you will have to compile Qt) or using the dynamic build. For the dynamic build, Qt will help you to resolve the dependencies:
macdeployqt is rather easy to use. Compile your app in release mode and call <qt_install_dir>/bin/macdeployqt <path_to_your_bundle>/<bundle>.app. After thats done, all Qt libraries are stored inside the <bundle>.app folder.
For windeployqt is basically the same: <qt_install_dir>\bin\windeployqt --release <path_to_your_build>\<application>.exe. All dependencies will be inside the build folder. (Hint: copy the <application>.exe in an empty directoy and run windeployqt on that path instead. This way you get rid of all the build-files).
Regarding the static build: Just google it, you will find hundreds of explanations for any platform. But unless you have no other choice but to use one single file (for whatever reason) it would recommend you to use dynamic builds. And regarding the user experience: On mac, they won't notice a difference, since in both cases everything will be hidden inside the app bundle. On windows, it's normal to have multiple files, so no one will bother. (And if you create an installer for windows, just make sure to add a desktop shortcut. This way the user will to have "a single file" to click.)

How to make Qt Creator add CEF framework to DEST_DIR on Mac OS X?

I'm working on a collaborative project in Qt Creator, and I've managed to get it to compile: I linked CEF Framework and the CEF dll wrapper. However, when I try to run it I get:
dyld: Library not loaded: #executable_path/Chromium Embedded Framework
Reason: image not found
As far as my understanding goes, the framework needs to be copied into my DEST_DIR, into .app/Contents/MacOS or something like that. I have NOT managed to make it work even by copying the framework there manually.
Also, since the development is meant to be cross platform, I was wondering if there's a way to tell qmake how to copy the framework to my DEST_DIR.
Any help in understanding how to deal with frameworks on Mac OS X in Qt Creator would be greatly appreciated.
As far as my understanding goes, the framework needs to be copied into my DEST_DIR, into .app/Contents/MacOS or something like that.
You're nearly there. Frameworks are generally copied into
.app/Contents/Frameworks
However, your bundle's executable contains a reference to where it expects those framework libraries are residing and having copied them into the app bundle, you need to tell the executable where they are.
Using oTool with -L argument, you can see the libraries referenced by the executable. You'd call it with the full path. For example
otool -L /Applications/Calculator.app/Contents/MacOS/Calculator
For each dylib in the framework, you need to fix up the path using the command line tool install_name_tool
When deploying a Qt application for Qt, we must run the macdeployqt. This essentially does the same thing for the Qt Frameworks; copies them into the relevant Frameworks folder and updates the paths.
I've not used it myself, but according to the documentation, macdeployqt supports handling 3rd party frameworks, with the option -executable=< path >