diff -uNr imlib2-1.6.1/src/lib/ximage.c imlib2-1.6.1.mod/src/lib/ximage.c
--- imlib2-1.6.1/src/lib/ximage.c	2019-11-08 21:08:08.000000000 +0200
+++ imlib2-1.6.1.mod/src/lib/ximage.c	2019-12-16 14:55:16.041906425 +0200
@@ -9,7 +9,8 @@
 #include <sys/mman.h>
 #endif
 #include <sys/ipc.h>
-#include <sys/shm.h>
+#include <linux/shm.h>
+#include <dlfcn.h>
 
 #include "ximage.h"
 
@@ -36,6 +37,79 @@
 /* temporary X error catcher we use later */
 static char         _x_err = 0;
 
+#ifndef shmid_ds
+# define shmid_ds shmid64_ds
+#endif
+
+static void * (*android_shmat)(int shmid, const void *shmaddr, int shmflg) = NULL;
+static int (*android_shmdt)(const void *shmaddr) = NULL;
+static int (*android_shmget)(key_t key, size_t size, int shmflg) = NULL;
+static int (*android_shmctl)(int shmid, int cmd, struct shmid_ds *buf) = NULL;
+
+static void * shmat(int shmid, const void *shmaddr, int shmflg) {
+	if (!android_shmat) {
+		void *handle = dlopen("@TERMUX_PREFIX@/lib/libandroid-shmem.so", RTLD_LOCAL | RTLD_LAZY);
+
+		if (!handle) {
+				abort();
+		}
+
+		android_shmat = dlsym(handle, "shmat");
+
+		dlclose(handle);
+	}
+
+	return android_shmat(shmid, shmaddr, shmflg);
+}
+
+static int shmdt(const void *shmaddr) {
+	if (!android_shmdt) {
+		void *handle = dlopen("@TERMUX_PREFIX@/lib/libandroid-shmem.so", RTLD_LOCAL | RTLD_LAZY);
+
+		if (!handle) {
+				abort();
+		}
+
+		android_shmdt = dlsym(handle, "shmdt");
+
+		dlclose(handle);
+	}
+
+	return android_shmdt(shmaddr);
+}
+
+static int shmget(key_t key, size_t size, int shmflg) {
+	if (!android_shmget) {
+		void *handle = dlopen("@TERMUX_PREFIX@/lib/libandroid-shmem.so", RTLD_LOCAL | RTLD_LAZY);
+
+		if (!handle) {
+				abort();
+		}
+
+		android_shmget = dlsym(handle, "shmget");
+
+		dlclose(handle);
+	}
+
+	return android_shmget(key, size, shmflg);
+}
+
+static int shmctl(int shmid, int cmd, struct shmid_ds *buf) {
+	if (!android_shmctl) {
+		void *handle = dlopen("@TERMUX_PREFIX@/lib/libandroid-shmem.so", RTLD_LOCAL | RTLD_LAZY);
+
+		if (!handle) {
+				abort();
+		}
+
+		android_shmctl = dlsym(handle, "shmctl");
+
+		dlclose(handle);
+	}
+
+	return android_shmctl(shmid, cmd, buf);
+}
+
 /* the function we use for catching the error */
 static int
 TmpXError(Display * d, XErrorEvent * ev)
