Reputation: 161
I have a C program that I want to package into an AppImage file. I am attempting to use linuxdeploy and appimagetool to create the AppImage for my program.
It has worked so far, but I do not know how to put resource files that are needed by my C program into the AppImage, nor do I know what code to use to load the files.
Currently, the code I am using to access the resource is this:
#include <stdio.h>
int main() {
FILE *file = fopen("resource.txt", "r"); //resource file is in the same directory as program
//more code to read file
fclose(file);
return 0;
}
I was package my program into an AppImage with these commands:
gcc program.c -o myprogram
./linuxdeploy-x86_64.AppImage --executable myprogram --desktop-file mydesktopfile --icon icon.png --appdir MyProgram.AppDir
ARCH=x86_64 ./appimagetool-x86_64.AppImage MyProgram.AppDir
Some other relevant info:
How should I package my program so it can still access the resource file, and how should I modify my code to read the resource file?
Upvotes: 0
Views: 165
Reputation: 161
I found a method that worked for me.
In the AppDir that was created, I added a folder resources
inside usr/share
, and put my resource file in that.
I then changed the code to this:
#include <stdio.h>
int main() {
FILE *file = fopen("resources/resource.txt", "r");
//more code to read file
fclose(file);
return 0;
}
This is the method that worked for me, but if anyone thinks that this is not a good way of doing this, feel free to comment.
One quick note, After some research, I found out that it is not possible to edit files inside an AppImage, that is by design. (think of an AppImage as an executable .ZIP file) So make sure that you're only opening the file to read it.
Upvotes: 0