In this article series, you will be told how to make an appimage file.

The first chapter will focus on running executables independently of the system. You should have intermediate knowledge of gnu/linux to understand this section clearly.

Static and dynamic binary concept

A statically compiled code can run without the need for any additional libraries. To understand whether a file is static or not, we need to look at that file with the ldd command.

$ ldd /bin/bash (0x00007ffc8f136000) => /lib/x86_64-linux-gnu/ (0x00007ff10adcd000) => /lib/x86_64-linux-gnu/ (0x00007ff10adc7000) => /lib/x86_64-linux-gnu/ (0x00007ff10ac02000)
/lib64/ (0x00007ff10af6c000)

As seen here, our file is compiled as dynamic, so its dependencies are listed. If our file was compiled as static, we should have obtained an output like the one below.

$ ldd test.bin not a dynamic executable

libc and interpreter concept

All dynamically compiled files are basically ve needs dependencies. from these files It is a basic C library. Thanks to this library, the program becomes able to perform its basic functions. is the interpreter and determines how the file will be run. To find which interpreter a file works with fillet We can use the command. is provided by the kernel and is not available as any file.

$ file /bin/bash /bin/bash: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/, for GNU /Linux 3.2.0, stripped


The dependency of an executable must usually be installed on the system. However, in some cases, it may need to be located in a different location than the system directories. In similar cases LD_LIBRARY_PATH By defining the environmental variable, the location of the additional directory where the library will be searched is specified.

$ ldd test.bin (0x00007ffc1c5c5000) => ​​not found => /lib64/ (0x00007feaab862000) /lib64/ld-linux-x86-64 .so.2 (0x00007feaaba76000)

In the example above We encountered a warning in our ldd output because the file could not be found in the system. Now let's try the same process again by defining our environmental variable.

$ export LD_LIBRARY_PATH=/home/user/test/libs/
$ ldd test.bin (0x00007ffe22bbc000) => /home/user/test/libs/ (0x00007f4c97790000) => /lib64/ (0x00007f4c97583000)
/lib64/ (0x00007f4c9779c000)

As you can see it found the library in the directory we defined.

In this way, if we copy all the dependencies of a file to a directory, we can run that file independently of the system.

$ ldd /bin/bash (0x00007fff2c359000) => /lib64/ (0x00007fce1e004000) => /lib64/ ( 0x00007fce1dfc5000) => /lib64/ (0x00007fce1ddcc000) => /lib64/ (0x00007fce1dd8c000) /lib64/ .2 (0x00007fce1e154000) # Now let's copy all the files to a directory called libs. $ mkdir libs $ ldd /bin/bash | cut -f3 -d" " | grep "^/" | sed "s/.*/install & libs\//g" | sh # You can use the above command to batch copy dependencies. $ ls libs # Now let's define our environmental variable. export LD_LIBRARY_PATH=/home/user/test/libs/ $ ldd /bin/bash (0x00007ffdeddc6000) => /home/user/test/libs/ ( 0x00007fd9ce7ea000) => /home/user/test/libs/ (0x00007fd9ce7ab000) => /home/user/test/libs/ (0x00007fd9ce5b2000) => /home/user/test/libs/ (0x00007fd9ce572000) /lib64/ (0x00007fd9ce926000)

In the example above, we pulled all the dependencies from their location in the system and copied them to a separate directory and made them use it from that directory. If you have noticed here, we did not copy the interpreter. This is because the interpreter is called by the file when we run the file. To overcome this situation, let's also copy the interpreter and the file to be run and run it as follows.

$ install /bin/bash ./ $ install /lib64/ ./ $ ./ --library-path "/home/user /test/libs/" ./bash --version GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu) ...

Now it is possible to run our program on any system with all its dependencies.

To the rest of our article here .