Good day,
I'm working on a Nim + QML panel for Linux, and been through the examples available in the nimqml github page as well as the nimqml-apps repositry, also in Github. The prototype application builds successfully and runs without issues other than being still a pre-alpha and lots of things not available yet. The problem is when I try to take the executable to another computer [ same operating system, same Qt versions, libDOtherSide installed in same way and path ] I can't get the executable to work, even on the development box if I move the executable to a different directory.
Therefore, is there a way to pack other files (resource files, like text files, svg images, jpg images...) into the Nim executable? I've been searching without much success on that topic. So I would certainly appreciate any hint on how to achieve this.
Thanks in advance, noxnivi
P.S.: as I couldn't post with the @noxnivi user, had to create a new one to be able to ask again. Apologies.
On Windows you could use resources and a resource compiler to accomplish this and I've tinkered with a similar mechanism on Linux and got it to work.
However, you should really figure out how to deploy applications on your OS of choice that can consist of more than one file.
The Qt Resource System: https://doc.qt.io/qt-6/resources.html
Nim example: https://github.com/filcuc/nimqml/tree/master/examples/resourcebundling
Good day,
Thanks all for your replies. @SpotlightKid, I had already been there, and tried the examples provided, also in the nimqml-apps repository that uses a different approach. Either way I end up with an executable i.e. Main and a resource file, Resource.rcc (after compiling the original .qrc file).
In fact, nimqml examples first make the .rcc file, and compiling doesn't do nothing to the resource file, just need to remember to add it to the package. On the other hand, the nimqml-apps ( https://github.com/R3D9477/nimqml-apps ) use a different approach, using NimScript to build a debug and a release version of the software. I had to tweak the code a bit for the nimqml-apps examples. In this case, the .rcc file is generated automatically by the NimScript file. Interesting approach.
I'm using the resource file to hold the GUI, made in QML, adding resources as stated in the Qt documentation. Therefore, @Araq, I don't see much sense in having the executable in /usr/bin and having the GUI somewhere else i.e. /etc/Main, or /opt/Main or anywhere else. That is why I'm trying to pack the resource along the Main Nim executable file.
@matkuki, @termer for what I've read on it, that seems to be what I was looking for. Need to dig into that and practice.
Thanks again all for your replies. Regards, noxnivi
Here's one way to do it with staticExec:
I don't see much sense in having the executable in /usr/bin and having the GUI somewhere else i.e. /etc/Main, or /opt/Main or anywhere else.
And I don't see the point in an UI app being in /usr/bin, but then I don't see the point in /usr/bin to begin with (distributing a single app over multiple different directories which all require root access is absurd crap) so please ignore me. ;-)
Either way I end up with an executable i.e. Main and a resource file, Resource.rcc (after compiling the original .qrc file).
So what. Just stick it next to your executable on windows (the nimqml example shows you how to get the path), or...
I don't see much sense in having the executable in /usr/bin and having the GUI somewhere else i.e. /etc/Main, or /opt/Main or anywhere else.
That is usually the *nix way, though. Binary in /usr/bin/foo and support files in /usr/share/foo or /usr/lib/foo (depending on whether they're arch-independant or not) .
But here's a way to compile the Qt resources (the main.qml in this example) into the executable:
# Create a 'resources.qrc' file with the following:
#
# <RCC>
# <qresource prefix="/">
# <file>main.qml</file>
# </qresource>
# </RCC>
#
# Then generate 'resources.hh' with:
#
# rcc --namespace -o resources.hh resources.qrc
#
# Then compile this file with `nim cpp`.
#
import NimQml
const resource_hh = "resources.hh"
{.passl: gorge("pkg-config --libs Qt6Core").}
proc qInitResources(): cint {.importcpp, header: resource_hh.}
proc qCleanupResources(): cint {.importcpp, header: resource_hh.}
proc mainProc() =
discard qInitResources()
defer: discard qCleanupResources()
var app = newQApplication()
defer: app.delete()
var engine = newQQmlApplicationEngine()
defer: engine.delete()
engine.load(newQUrl("qrc:/main.qml"))
app.exec()
when isMainModule:
mainProc()
GC_fullcollect()
Good day @Araq,
Well... Actually I have no relationship whatsoever with the System V devs, nor personal, nor profesional... The filesystem just came with the OS I use, not that I like it though. Agree with you on that, scattering files across the filesystem doesn't make much sense (wasted time searching for stuff already). I rather have a tidier approach, and a better organized filesystem... but that I can't choose right now XD.
That is why I like the zipapp, every file required by the Python "software" is packed in a zipped file that is executable.
Something like that on Nim would be great too. That or use Application Directories, as ROX did. Or just put everything in a folder, add an attribute to the folder, and make a daemon that checks if the folder is double clicked launches the software inside... thinking aloud here.
Regards, noxnivi
Good day @SpotlightKid,
Never seen that approach with Nim. I know resources can be embedded in the binary if it is C++. I'll research and try what you wrote. Thanks for pointing out such method.
Regards, noxnivi
I rather have a tidier approach, and a better organized filesystem... but that I can't choose right now XD.
Well you can put the app directory into /opt or similar and have your users double click on the executable. Pretty much the same as an app bundler.