Qt .nib issues on MacOS - c++

I'm trying to deploy a Qt C++ application on another mac that doesn't have Qt installed. I am getting a "Qt internal error: qt_menu.nib could not be loaded. The .nib file should be placed in QtGui.framework/Versions/Current/Resources/ or in the resources directory of your application bundle."
I've tried packing qt_menu.lib into both suggested places, with no success:
$ ls ./arya.app/Resources/
qt_menu.nib
$ ./arya.app/Contents/MacOS/arya
Qt internal error: qt_menu.nib could not be loaded. The .nib file should be placed in QtGui.framework/Versions/Current/Resources/ or in the resources directory of your application bundle.
or:
$ mkdir QtGui.framework
$ mkdir QtGui.framework/Versions/
$ mkdir QtGui.framework/Versions/Current/
$ mkdir QtGui.framework/Versions/Current/Resources
$ mv ./arya.app/Resources/qt_menu.nib QtGui.framework/Versions/Current/Resources/
$ ./arya.app/Contents/MacOS/arya
Qt internal error: qt_menu.nib could not be loaded. The .nib file should be placed in QtGui.framework/Versions/Current/Resources/ or in the resources directory of your application bundle.
I'm not sure if there may be some connection, but I had some issues with dylib paths before this. After stumbling about with install_name_tool, I 'solved' them with:
export DYLD_LIBRARY_PATH=.
before running the application.
Building the application with
CONFIG -= app_bundle
made no difference.

After battling this same problem from another application, I've managed to pin down the exact commands that easily solve this .nib issue:
mkdir -p application.app/Contents/Frameworks/QtGui.framework/Resources
cp -r $(QTLIBDIR)/QtGui.framework/Versions/4/Resources/qt_menu.nib application.app/Contents/Frameworks/QtGui.framework/Resources
This does not address other issues on deploying for mac - just the .nib problem.

Try this:
(1) Remove your export DYLD_LIBRARY_PATH=.
(2) Remove your CONFIG -= app_bundle
(3) Put QT frameworks into ./arya.app/Contents/Frameworks
I.e. all the contents of QtGui.framework into ./arya.app/Contents/Frameworks/QtGui.framework,
QtCore.framework into ./arya.app/Contents/Frameworks/QtCore.framework, etc.
So your qt_menu.nib will automatically be a ./arya.app/Contents/Frameworks/QtGui.framework/Versions/Current/Resources/qt_menu.nib

Try running macdeployqt on your .app after building it. It copies the needed Qt frameworks (and any other needed dylibs) into the bundle and fixes up the binary's link paths so it knows to link in Qt from it's own bundle.
(It also has a bug that causes any libraries with paths not ending in lib/ (like /opt/local/lib/opencv/cv.lib to not be copied correctly, but there's a one-line source fix for this)

Related

Error while loading shared object file: No such file or directory

I am trying to generate a usable binary for GCBM, a C++ carbon accounting tool. The binary has been generated from a GitHub Action workflow which is available as an artifact here: https://nightly.link/HarshCasper/moja.canada/actions/runs/1999997115/GCBM.zip
I downloaded the ZIP, unzipped it inside a gcbm directory, cd inside it, and tried launching the binary through:
./moja.cli
I got the following error:
./moja.cli: error while loading shared libraries: libmoja.flint.so.1: cannot open shared object file: No such file or directory
I have tried various ways to fix it by following other StackOverflow threads but nothing really has worked out. Can anyone please help me solve it?
From the error, it's clear library path that the executable looking for is not present. It happens sometimes if the executable compiled on another system takes a hardcoded library path that is not present on your system. The solution is you have to compile source on your system. Better compile it with a STATIC library. Make changes to Cmake(https://github.com/HarshCasper/moja.canada/blob/bffb196222e118e6797afa2bedab02dbe29dd330/Source/CMakeLists.txt#L47). or copy shared library to proper path.
Example, how to run GCBM/moja.cli with the ~40 internal shared libraries
mkdir GCBM && cd GCBM/
unzip GCBM.zip
chmod +x moja.cli
## create a script moja.sh to run moja.cli :
#!/bin/sh
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
exec ./moja.cli
## make the script executable and run ./moja.sh

MinGW Compiler Errors - How do I setup the MSYS bat?

I'm running Windows 8.
I installed the MinGW compiler to the default C:\ directory using the GUI installer. I selected to install all the elements available in the Basic Setup package of the MinGW Installation Manager.
After the installation completed, I checked that "C:/MinGW/msys/1.0/etc/fstab" had the one line of C:/MinGW /mingw and an open line beneath it. I also created a shortcut to msys.bat in the Start menu.
Then I rebooted my machine.
I created a folder called "CompileBin" in the C:\ directory, so C:\CompileBin\ and then I placed my test.cpp file inside, so C:\CompileBin\test.cpp
I ran msys.bat and the console opened up. It showed:
MyName,#MyLaptopsName ~
$
I started to navigate to where my test.cpp is:
cd c:\CompileBin\
Now the prompt looked like this:
MyName,#MyLaptopsName ~
$ cd c:\CompileBin\
>
I entered the dir command to look around and got the response:
MyName,#MyLaptopsName ~
$ cd c:\CompileBin\
> dir
sh: cd: c:CompileBindir: No such file or directory
Okay, so I figured maybe the path wasn't set up.
I added PATH to the Environment Variables (because it was NOT originally there) and gave it the value C:\MinGW\bin;
I still get the same error.
Unix tooling requires forward slashes in path names. It is cd c:/CompileBin

How to deploy Qt applications for Linux

I followed all the steps successfully as mention in the Qt documentation:
Qt for Linux/X11 - Building from Source
Qt for Linux/X11 -
Deployment
But I still couldn't make static Qt application, the executable generated by the above documented steps still needs Qt shared objects on other system.
Any ideas?
You need to deploy the application, for this purpose I use the utility
cqtdeployer
This utility itself collects all the necessary dependencies of your application and you do not have to spend your time on it, or you can automate this process.
You can install from github releases (Windows)
or
from snapstore (Linux)
sudo snap install cqtdeployer
You can use as follows:
Windows:
%cqtdeployer% -bin myApp -qmake path/to/Qt/5.x.x/build/bin/qmake.exe -qmlDir path/to/my/qml/files/dir
Linux:
cqtdeployer -bin myApp -qmake path/to/Qt/5.x.x/build/bin/qmake -qmlDir path/to/my/qml/files/dir
path/to/Qt/5.x.x/build/bin/qmake - This is the way qmake is used to build your program.
path/to/my/qml/files/dir - this is the path directly to your qml file (which you wrote)
And Run application with sh script (Linux) or exe (Windows)
If you'll use the version from snap then make sure that you have all the permissions.
If you need use windows version just install application from installer
Updated
If you want create a simple installer for you application just add qif option for command of cqtdeployer.
Example :
cqtdeployer -bin myApp -qmake path/to/Qt/5.x.x/build/bin/qmake -qmlDir path/to/my/qml/files/dir qif
Details on all the intricacies of cqtdeployer can be found on the official wiki project.
The best way to deploy your application is not necessarily to statically link it for the following reasons:
LGPL licencing means that your application must now be made public and may not sold (I think) - i.e. since its statically linked and the qt libs are within your executable your executable is now part of the open source.
Its a massive pain in the arse... I have gone around this loop and know the pain well.
Installing qt-everywhere is also not so great, I just don't see how you can garantee that the libraries will be the same version as the ones that your program needs.
So what I started to do was create my own script to deploy qt for me. The basic "jist" of this is that you use ldd to find out which qt libraries you need and copy them into a sub folder (./lib) within the same folder as your executable to make an install bundle.
Note: on Windows there is a deployqt application which does somthing similar (can't remember exactly what it is called).
Below I have copied a version of my deploy script. Note that it is quite old now, but I don't see why it should not work (its not written particularly well), but if not it will give you a start place. Also look out for the plugin's. In this script I have added code to copy the audio plugin since I was using that. If you are using other plugins then you will need to copy those (they are usually in sub dir's of the qt libs like .../audio)... I had a todo to try to figure out what plugins are needed from the .pro file but I never got around to that (I would have to pass in the .pro file to this script as well)...
To run, just run this script and pass in the directory that your executable lives in.
#!/bin/bash
# Rememeber start dir
START_DIR=$PWD
# Determine which dir to deploy in and cd to that dir
if [ -d "$1" ]; then
DEPLOY_DIR=$1
else
DEPLOY_DIR=$PWD
fi
echo "Deploy dir: $DEPLOY_DIR"
cd $DEPLOY_DIR
# Run ldd on all files in the directory and create a list of required qt libs
flag=false
for entry in `ldd $DEPLOY_DIR/* | grep -i qt`; do
if $flag; then
# Only add to the array if it is not already in it
if ! [[ $libsArray =~ $entry ]]; then
echo "adding $entry"
libsArray="$libsArray $entry"
fi
flag=false
fi
# If we see a "=>" then the next line will be a library
if [ $entry == "=>" ]; then
flag=true
fi
done
echo
echo
# Create the required folder structure. Note here we are need the qt audio plugin so we are going to manually copy that as well.
mkdir -p lib
mkdir -p lib/audio
# Now copy these files to the deploy directory
for entry in $libsArray; do
echo "cp -v -f $entry $DEPLOY_DIR/lib"
cp -v -f $entry $DEPLOY_DIR/lib
done
# Now get the audio lib - this is a plugin that we are using so we need these libs as well.
# Add other plugins here as well.
# TODO: maybe we can read this in from the *.pro file.
cp -v -f `qmake -query QT_INSTALL_BINS`/../plugins/audio/* $DEPLOY_DIR/lib/audio
# Go back to start dir
cd $START_DIR
Once you have all the files you need you should be able to copy the whole lot to another PC and run it. Note: you may have to set the export LD_LIBRARY_PATH=<path-to-libs> so that the libs can be found... or install the libs into somewhere like /usr/lib/your-appplication/.
But installing libs is another question/subject!

Building PostgreSQL driver for Qt

I trying to build psql driver but have some unexpected messages.
maxim#maxim-VirtualBox:~/Downloads/distrib/qt-everywhere-opensource-src-5.2.1/qtbase/src/plugins/sqldrivers/psql$ qmake psql.pro
Cannot read
/home/maxim/Downloads/qt-everywhere-opensource-src-5.2.1/qtbase/mkspecs/modules-inst/qt_lib_bootstrap_private.pri:
No such file or directory
...
Cannot read
/home/maxim/Downloads/qt-everywhere-opensource-src-5.2.1/qtbase/mkspecs/modules-inst/qt_lib_xml_private.pri:
No such file or directory
But all of these files exist. What is the problem?
The problem seems to be that you have "modules-inst" as the subfolder name, whereas it is only "modules" without the "-inst" suffix in reality.
See how it works fine on my end:
lpapp ~/Downloads/qt-everywhere-opensource-src-5.2.1/qtbase/src/plugins/sqldrivers/psql $ qmake psql.pro
lpapp ~/Downloads/qt-everywhere-opensource-src-5.2.1/qtbase/src/plugins/sqldrivers/psql $
I found a problem. After install qt-libraries I created new folder 'distrib' and move sources in there. That's why I got this problem.
I should have checked the existence of the directory by cd command.

boost thread link fails in Netbeans 7.1 debugging/testing session

I am developing an app on Netbeans, while I can run it. I can not debug or reun the test files. When I try to do so, I get:
./build/Debug/GNU-Linux-x86/tests/TestFiles/f1: error while loading shared libraries: libboost_thread.so.1.49.0: cannot open shared object file: No such file or directory
It tried including the library or the specific file with the debugging or testing session, but I continue to get that. Could there be an inconsistency with Netbeans?
Any ideas would be greatly appreciated!
I assume your OS is Linux. It follows from your email that you have access to the copy of the libboost_thread.so.1.49.0 file. Let DIR be directory where this library exists.
If you do not have superuser on this computer, use method A. If you have superuser, use method A or method B.
Method A. Good for non-superuser or for superuser.
Let DIR be directory in which library libboost_thread.so.1.49.0 exists.
I assume you can start NetBeans from shell command line, not from GUI icon.
Quit NetBeans. Execute following command in bash:
export LD_LIBRARY_PATH=DIR:$LD_LIBRARY_PATH
start netbeans from command line
Eventually, you will want to put the export command into your ~/.bashrc file.
Method B. Good only for superuser.
If you have superuser, use one the following methods to place the missing library into /usr/lib or /lib:
(1) install boost from rpm or apt or whatever packaging your linux system has, or
(2) install boost from sources with --prefix=/usr, or
(3) copy the mentioned library to /usr/lib. If you have to use #3, be careful about symlinks. Copy using "cp -a" and copy all files beginning libboost_thread.so*, like
cp -a DIR/libboost_thread.so* /usr/lib