Dealing with files in app running inside AppImage - c++

I have an application written in Qt/C++ which is running under Linux.
Inside my application I have several functions which dealing with files located in:
QCoreApplication::applicationDirPath()
/tmp/
QStandardPaths::ConfigLocation
QStandardPaths::DataLocation
The application runs smoothly if executes as regular Linux executable. However there are problems if I pack it into AppImage. It doesn't see files in expected locations and can't create new files in there.
If I understand AppImage correctly - it is SquashFS which is readonly. So this behavior is understandable. But how can I deal with? Is that possible to solve this problem without changing source code of my app?
The output of QCoreApplication::applicationFilePath() when run the Linux executable is "/home/mike/projects/builds/build-testqtapp-Desktop_Qt_5_12_8_GCC_64bit-Debug/AppDir/testqtapp" The output of the same command from AppImage is "/tmp/.mount_testqtyEZUuH/testqtapp"

Related

Deploy Qt application on Linux [duplicate]

This question already has an answer here:
Deploying Qt applications in Linux properly
(1 answer)
Closed 4 years ago.
I have created a nice little scientific Qt application and I want to distribute it.
It was very easy to do this in Windows, I simply created a folder, put my executable there and called the windeployqt program, which put all necessary .dll files in the folder like Qt5Core.dll, Qt5Gui.dll, Qt5Charts.dll... and it created some subfolders like iconengines/, imageformats/, platforms/ and many more.
All together this folder now contains 43 files.
When I copy this folder to any other computer with Windows 10 it runs well.
I would like to do the same on Linux, because it is the preferred operating system that we use.
However, I struggle a bit because I do not really know how to start.
Is it possible to do it the same way? Copy all necessary libraries in a folder together with the executable and simply be able to copy it on a different computer with Linux and run it?
(To clarify: When I say Linux I mean Ubuntu 18.04 or 16.04)
Or is there a different way how to do it?
I only have a students license so I think I'm not allowed to statically link the libraries (but I have to read the license terms again to be sure)
In case it works the same. Is there a simple way to copy all necessary libraries in this folder? Or do I have to search the 42 libraries by myself?
I have read the manual but to be honest I did not understand everything and all the example codes in there.
Thank you for your help.
Look at the Creating the Application Package link in the documents. For Linux, a starting script is given to you via documentation as a starting point. Here it is:
#!/bin/sh
appname=`basename $0 | sed s,\.sh$,,`
dirname=`dirname $0`
tmp="${dirname#?}"
if [ "${dirname%$tmp}" != "/" ]; then
dirname=$PWD/$dirname
fi
LD_LIBRARY_PATH=$dirname
export LD_LIBRARY_PATH
$dirname/$appname "$#"
This script must be saved as an .sh script and must live in the directory of your executable.
Make the script executable , open a terminal and do the following:
$ cd /pathToScript/
$ sudo chmod +x scriptName.sh
Then double click on your script to run.
As stated in the Qt docs this will make:
...sure that the Qt libraries will be found by the dynamic linker. Note that you only have to rename the script to use it with other applications.
If you want to statically deploy your project, you must first have a static version of Qt built from source, that can be found at this headline from the Qt Docs.
A couple more notes: If you want to distribute this project for it to be used on a Linux system. You can simply package the build folder. But to actually run it, you would need to use the script (for the easy way at least) on a Linux system. It is not necessary to go hunting for the application's dependencies.
You need to install all qt libraries first.
I think using qmake could be a solution if you're creating a Qt-based project. Qt Creator uses it as default.
qmake generates all needed files used to compile the program. Try using it.

Processing.exe Doesn't Respond to System() (c++)

I exported my Processing project, which renders as P3D, successfully. The .exe file works, even from the command line. I need to run this executable from a c++ program. When I call
system("Project_name.exe");
on it, it doesn't open up the file. I checked the path by opening other types of files like .txt successfully. I also tried it with system("start Project_name.exe")and it gives the same input.
Is it because its not reading java with the app properly? The java folder is also in the same directory. I am using VS 13 Pro. Please help!
Note: I understand system calls are not the best approach. I also used CreateProcess but was not successful. I think the file is opened but the frame and contents doesn't display.
Thank you
System command works fine in case of interactive applications, starting notepad works fine.
Please ensure your application and dependencies are picked up from the right path, You may try to set path environment variable within c++ application.
If you are able to run this application from command line, you may write a batch file to invoke your application and invoke this batch file from c++ application using system command

Making .exe file in Visual Studio 2013

I have made my project in C++ and used SFMl 2.1, I also have loaded images from disk and when I'm trying to run its .exe file its giving error in image loading.
For now I'm trying to run its own .exe fie (in Debug or Release folder of project).
i want to make this .exe file for my friends who are not programmers so that my game would run on their PCs as well.
If someone know to make .exe so please help!
First, try to put the images beside the exe file.
After that, your friends probably won't have all the development DLL and libs needed for your app to work. You can use depends.exe to know what is needed for your app to start. Put all those file beside your exe and it should work on most PCs.
Bonus tip
Often, when you experience this kind of problem (application crash when starting directly outside the project), the simplest solution, which is language-agnostic, is to make your app write to a new file within your main function and look where it ends up in your project hierarchy after you ran your app directly (outside the IDE/project).
You'll see right there where the relative root of your app is. Most of the time, it's right next to the compiled file, depending on the language you chose.

Launching a stand-alone executable from C++

I have a programmable signal generator. It came with a .inf file and a .exe file. Double clicking the .exe file runs the signal generator systems application.
I would like to invoke this executable from a piece of VC++ code. I am using Shell Execute as follows.
std::string app = "C:\gen.exe";
ShellExecute(NULL,"open",NULL,app.c_str(),NULL,SW_SHOWNORMAL);
However, instead of launching the executable, the command pops open a file dialog.
Upon further experimenting with ShellExecute, I noticed that ShellExecute works for executable files in the Program Files directory, but fails when I have stand alone executables such as in the case I mentioned above. Can someone please explain how to launch using VC++ a standalone executable located in a random directory on the disk?
By Standalone executable, I mean that the binary distribution for the application was simply an executable file, and a couple of other files. I can launch the executable by simply double clicking it, however, I cannot launch it using ShellExecute.
If you take a look at the documentation for ShellExecute (link), it seems like you might have the reference to app in the wrong parameter. The fourth parameter is the parameters parameter - not the parameter specifying which file to open/run. So basically, this should work:
std::string app = "C:\\gen.exe";
ShellExecute(NULL,"open",app.c_str(),NULL,NULL,SW_SHOWNORMAL);
Alternatively, you could use CreateProcess or system("C:\\gen.exe");. I should point out that none of these options are portable to other OSs, but running a program probably won't be, however you end up doing it, since most OSs differ on how they run programs - or even what programs are.

C++ Embed external .exe into my compiled .exe

I have a quick question on a topic that I'm quite a noob about. I have a program I made that sends a command to another .exe in a folder I called "tools". I send it in this format:
system("tools\\program.exe -r -w file.dat file_new.dat");
Everything works great, however, when I build my program into a .exe it will require the other executable to be in a second folder, obviously. Is there any way to include the external .exe into my project so the final product is just one .exe?
I am using Visual Studio 2008 (lol) and run windows 7 64bit.
Thanks :)
Typically, the management of external dependencies would be handled by the installer. NSIS is my favoured solution for the Windows platform.
The alternative: Convert the binary to a base64 encoding and embed it as a header file in your project. When the application is run, convert the base64 representation of the exe to a binary sequence and then output that sequence of bytes to a file in a temporary directory (like C:\windows\temp or %AppData%\Local\Temp). Then run the exe. Once you're done with it, remove the exe.
You can add the file to resources. And before the command is executed, you can check, if the second executable exists. If it doesn't exist, you have to extract the data from resource and store to the file...
This thread was dealing with reading html from resource. It is very similar with binary file.