python源码github下载:https://github.com/python/cpythonhttps://github.com/python/cpython/releases/tag/2.7

python2源码编译

编译主机环境:

Distributor ID: Ubuntu
Description:    Ubuntu 24.10
Release:        24.10
Codename:       oracular

Linux ubuntu-main 6.11.0-13-generic #14-Ubuntu SMP PREEMPT_DYNAMIC Sat Nov 30 23:51:51 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

编译问题

1.configure: error: installation or configuration problem: C compiler cannot create executables.

root@ubuntu-main:/home/xinyi/python/Python-2.0# sudo ./configure 
loading cache ./config.cache
checking MACHDEP... linux6
checking for --without-gcc... no
checking for --with-cxx=<compiler>... no
checking for gcc... gcc
checking whether the C compiler (gcc  ) works... no
configure: error: installation or configuration problem: C compiler cannot create executables.

通过查看configure源码,得知查看config.log,找到configure:911:1: error: return type defaults to 'int' [-Wimplicit-int],将911行的main函数加上int返回值类型即可。

2../../Include/pyport.h:372:2: error: #error "could not set LONG_MAX in pyport.h"

make[1]: 进入目录“/home/xinyi/python/Python-2.0/Parser”
gcc -g -O2 -Wall -Wstrict-prototypes -I./../Include -I.. -DHAVE_CONFIG_H   -c -o pgenmain.o pgenmain.c
In file included from ./../Include/pymem.h:7,
                 from ./../Include/pgenheaders.h:24,
                 from pgenmain.c:16:
./../Include/pyport.h:372:2: error: #error "could not set LONG_MAX in pyport.h"
  372 | #error "could not set LONG_MAX in pyport.h"
      |  ^~~~~
make[1]: *** [<内置>:pgenmain.o] 错误 1
make[1]: 离开目录“/home/xinyi/python/Python-2.0/Parser”
make: *** [Makefile:195:Parser] 错误 2

#### failed to build some targets  ####

定义#define SIZEOF_LONG 8即不会报错

#define SIZEOF_LONG 8
#ifndef LONG_MAX
#if SIZEOF_LONG == 4
#define LONG_MAX 0X7FFFFFFFL
#elif SIZEOF_LONG == 8
#define LONG_MAX 0X7FFFFFFFFFFFFFFFL
#else
#error "could not set LONG_MAX in pyport.h"
#endif
#endif

3. static declaration of ‘xx’ follows non-static declaration`

1)listobject.c:1547:21: error: static declaration of ‘immutable_list_type’ follows non-static declaration

listobject.c:1547:21: error: static declaration of ‘immutable_list_type’ follows non-static declaration
 1547 | static PyTypeObject immutable_list_type = {
      |                     ^~~~~~~~~~~~~~~~~~~

static改为extern

2)./threadmodule.c:156:21: error: static declaration of ‘Locktype’ follows non-static declaration

static改为extern

3)

./_sre.c:1804:25: error: static declaration of ‘Pattern_Type’ follows non-static declaration
 1804 | statichere PyTypeObject Pattern_Type = {
      |                         ^~~~~~~~~~~~
./_sre.c:1170:28: note: previous declaration of ‘Pattern_Type’ with type ‘PyTypeObject’ {aka ‘struct _typeobject’}
 1170 | staticforward PyTypeObject Pattern_Type;
      |                            ^~~~~~~~~~~~
./_sre.c:2203:25: error: static declaration of ‘Match_Type’ follows non-static declaration
 2203 | statichere PyTypeObject Match_Type = {
      |                         ^~~~~~~~~~
./_sre.c:1171:28: note: previous declaration of ‘Match_Type’ with type ‘PyTypeObject’ {aka ‘struct _typeobject’}
 1171 | staticforward PyTypeObject Match_Type;
      |                            ^~~~~~~~~~
./_sre.c:2311:25: error: static declaration of ‘Scanner_Type’ follows non-static declaration
 2311 | statichere PyTypeObject Scanner_Type = {
      |                         ^~~~~~~~~~~~

statichere改为extern

太多这种static语法,这么改下去没有尽头,果断放弃。

最终使用github官方源码编译,就没有上面这些乱七八糟的问题了。


0 条评论

发表回复

您的电子邮箱地址不会被公开。