交叉編譯
下載並解壓縮後,首先在目錄中執行 (需先編譯一次PC可執行的版本)
ln -s /openssl-1.1.1w/include/openssl/ ./Include/
CPPFLAGS="$CPPFLAGS -D__ANDROID_API__=23" \
./configure --host=arm-linux-androideabi --build=x86_64-pc-linux-gnu \
LDFLAGS="-L/lib/ -lintl -lffi " \
CFLAGS="-I./Include/ -I/usr/include/" \
--prefix="/Python-3.13.0/install-local" \
--with-build-python=../Python-3.13.0.X86/python \
--with-openssl=/openssl-1.1.1w/ \
--with-mimalloc=no --disable-ipv6 --enable-shared --enable-profiling \
ac_cv_buggy_getaddrinfo=no ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no ac_cv_func_gethostbyname_r=no \
ac_cv_search_login_tty=no ac_cv_func_splice=no ac_cv_libatomic_needed=yes
我會使用到 openssl功能,所以要修改 Modules/Setup
SSL=/openssl-1.1.1w/
_ssl _ssl.c $(OPENSSL_INCLUDES) $(OPENSSL_LDFLAGS) $(SSL)libssl.a $(SSL)libcrypto.a
修改 pyconfig.h 內的參數,關掉編譯過不了的
// #define HAVE_LOGIN_TTY 1 (改0無效) ### ac_cv_search_login_tty=no
// #define HAVE_SPLICE 1 (改0無效) ### ac_cv_func_splice=no
修改 Makefile
LIBS 增加 -latomic
刪除 -luuid (有一個地方)
刪除 _uuid (有兩個地方)
中間遇到很多使用到沒有定義的func,在使用到的上面加對應的定義即可。
(不可全加在.c的最上面)
### Modules/posixmodule.c
extern char* ttyname(int __fd); /* unistd.h */
extern pid_t wait3(int *, int, struct rusage *);
int lockf(int, int, off_t); /* bits/lockf.h */
ssize_t preadv(int, const struct iovec*, int, off_t); /* sys/uio.h */
ssize_t pwritev(int, const struct iovec*, int, off_t); /* sys/uio.h */
extern int mkfifoat(int, const char*, mode_t); /* sys/stat.h */
### Modules/signalmodule.c
extern int sigwaitinfo(const sigset_t*, siginfo_t*); /* signal.h */
extern int sigtimedwait(const sigset_t*, siginfo_t*, const struct timespec*); /* signal.h */
### Modules/socketmodule.c
//#include <net/if.h>
struct if_nameindex {
unsigned if_index;
char* if_name;
};
char* if_indextoname(unsigned, char*);
unsigned if_nametoindex(const char*);
struct if_nameindex* if_nameindex(void);
void if_freenameindex(struct if_nameindex*);
extern int sethostname(const char *, size_t); /* bionic/libc/include/unistd.h */
### Modules/_testexternalinspection.c
//#if defined(__USE_GNU)
ssize_t process_vm_readv(pid_t, const struct iovec*, unsigned long, const struct iovec*, unsigned long, unsigned long);
ssize_t process_vm_writev(pid_t, const struct iovec*, unsigned long, const struct iovec*, unsigned long, unsigned long);
//#endif
遇到的坑
遇到下述的錯誤:
arm-linux-androideabi-gcc ...()... -o Objects/typevarobject.o Objects/typevarobject.c
In file included from ./Include/internal/pycore_unicodeobject.h:15:0,
from ./Include/internal/pycore_floatobject.h:12,
from ./Include/internal/pycore_runtime.h:15,
from ./Include/internal/pycore_pystate.h:12,
from ./Include/internal/pycore_call.h:12,
from Objects/typeobject.c:5:
./Include/internal/pycore_global_strings.h:791:40: error: 'struct <anonymous>' has no member named '_py_set'
(_Py_SINGLETON(strings.identifiers._py_ ## NAME._ascii.ob_base))
^
./Include/internal/pycore_global_objects.h:28:31: note: in definition of macro '_Py_GLOBAL_OBJECT'
_PyRuntime.static_objects.NAME
^
./Include/internal/pycore_global_strings.h:791:7: note: in expansion of macro '_Py_SINGLETON'
(_Py_SINGLETON(strings.identifiers._py_ ## NAME._ascii.ob_base))
^
Objects/typeobject.c:10164:38: note: in expansion of macro '_Py_ID'
PyDoc_STR(DOC), .name_strobj = &_Py_ID(NAME)}
^
Objects/typeobject.c:10241:5: note: in expansion of macro 'TPSLOT'
TPSLOT(__set__, tp_descr_set, slot_tp_descr_set, wrap_descr_set,
^
Makefile:3016: recipe for target 'Objects/typeobject.o' failed
make: *** [Objects/typeobject.o] Error 1
make: *** Waiting for unfinished jobs....
#### make failed to build some targets (1 seconds) ####
改法:
在下面這行的上方
TPSLOT(__set__, tp_descr_set, slot_tp_descr_set, wrap_descr_set,
"__set__($self, instance, value, /)\n--\n\nSet an attribute of instance to value."),
增加 #undef __set__ (因為__set__是保留關鍵字)
沒有留言:
張貼留言