| 103 | And for the last step, we need to edit the ''src/global_libpython_loader.cpp'' file: |
| 104 | |
| 105 | * changing ''#ifdef !__linux!__'' into ''#ifndef !__linux!__'' (so that the stuff we need will be used on Android) |
| 106 | |
| 107 | * remove a GNU macro an linh.h file (both are broken on Android and break the build): |
| 108 | |
| 109 | {{{ |
| 110 | #define _GNU_SOURCE |
| 111 | #include <link.h> |
| 112 | }}} |
| 113 | |
| 114 | * add a few headers file needed for compilation on Android (found by studying compile errors): |
| 115 | |
| 116 | {{{ |
| 117 | #include <dlfcn.h> |
| 118 | #include <link.h> |
| 119 | }}} |
| 120 | |
| 121 | The resulting file looks like this: |
| 122 | |
| 123 | {{{ |
| 124 | /** |
| 125 | * PyOtherSide: Asynchronous Python 3 Bindings for Qt 5 |
| 126 | * Copyright (c) 2013, Thomas Perl <m@thp.io> |
| 127 | * |
| 128 | * Permission to use, copy, modify, and/or distribute this software for any |
| 129 | * purpose with or without fee is hereby granted, provided that the above |
| 130 | * copyright notice and this permission notice appear in all copies. |
| 131 | * |
| 132 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH |
| 133 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 134 | * FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, |
| 135 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
| 136 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
| 137 | * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 138 | * PERFORMANCE OF THIS SOFTWARE. |
| 139 | **/ |
| 140 | |
| 141 | #include "global_libpython_loader.h" |
| 142 | |
| 143 | namespace GlobalLibPythonLoader { |
| 144 | |
| 145 | #ifndef __linux__ |
| 146 | |
| 147 | #include <stdio.h> |
| 148 | #include <string.h> |
| 149 | |
| 150 | #include <dlfcn.h> |
| 151 | #include <link.h> |
| 152 | |
| 153 | static int load_python_globally_callback(struct dl_phdr_info *info, size_t size, void *data) |
| 154 | { |
| 155 | int major, minor; |
| 156 | const char *basename = strrchr(info->dlpi_name, '/'); |
| 157 | int *success = (int *)data; |
| 158 | |
| 159 | if (basename != NULL) { |
| 160 | if (sscanf(basename, "/libpython%d.%d.so", &major, &minor) != 2) { |
| 161 | if (sscanf(basename, "/libpython%d.%dm.so", &major, &minor) != 2) { |
| 162 | return 0; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | void *pylib = dlopen(info->dlpi_name, RTLD_GLOBAL | RTLD_NOW); |
| 167 | if (pylib != NULL) { |
| 168 | *success = 1; |
| 169 | } else { |
| 170 | fprintf(stderr, "Could not load python library '%s': %s\n", |
| 171 | info->dlpi_name, dlerror()); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | bool loadPythonGlobally() |
| 179 | { |
| 180 | int success = 0; |
| 181 | dl_iterate_phdr(load_python_globally_callback, &success); |
| 182 | return success; |
| 183 | } |
| 184 | |
| 185 | |
| 186 | #else /* __linux__ */ |
| 187 | |
| 188 | bool loadPythonGlobally() |
| 189 | { |
| 190 | /* On non-Linux systems, no need to load globally */ |
| 191 | return true; |
| 192 | } |
| 193 | |
| 194 | #endif /* __linux__ */ |
| 195 | |
| 196 | }; /* namespace GlobalLibPythonLoader */ |
| 197 | |
| 198 | }}} |
| 199 | |
| 200 | This last change makes !PyOtherSide compile with the crippled Bionic C library used on Android. |
| 201 | |
| 202 | '''The resulting project should look like contents of this tarball:''' |
| 203 | |
| 204 | Now you should be able to build the !PyOtherSide project by pressing the "rebuild" button in !QtCreator. |
| 205 | |