Mac OS 10.6/Snow Leopard上的Python构建问题

2 投票
2 回答
4515 浏览
提问于 2025-04-15 18:57

我在Snow Leopard上遇到了构建Python 2.6.4的问题。

  • 操作系统:Mac OS X 10.6
  • 处理器:Yonah CPU,32位
  • 编译器:gcc-4.2.1

更新 I

通过从CFLAGS中删除所有非标准的包含文件和库解决了这个问题(里面有一个uuid/uuid.h)。尽管下面描述的错误仍然存在,但它还是编译成功了,/usr/include/hfs/hfs_format.h:765是个关键点。对于好奇或有资源的人,这里是相关的源文件:

$ cat /usr/include/hfs/hfs_format.h
...
748 #include <uuid/uuid.h>
749 
750 /* JournalInfoBlock - Structure that describes where our journal lives */
751 
752 // the original size of the reserved field in the JournalInfoBlock was
753 // 32*sizeof(u_int32_t).  To keep the total size of the structure the 
754 // same we subtract the size of new fields (currently: ext_jnl_uuid and
755 // machine_uuid).  If you add additional fields, place them before the
756 // reserved field and subtract their size in this macro.
757 //
758 #define JIB_RESERVED_SIZE  ((32*sizeof(u_int32_t)) - sizeof(uuid_string_t) - 48)
759 
760 struct JournalInfoBlock {
761         u_int32_t       flags;
762         u_int32_t       device_signature[8]; // signature used to locate device.
763         u_int64_t       offset;        // byte offset to the journal on the device
764         u_int64_t       size;          // size in bytes of the journal
765         uuid_string_t   ext_jnl_uuid;
766         char            machine_serial_num[48];
767         char            reserved[JIB_RESERVED_SIZE];
768 } __attribute__((aligned(2), packed));
769 typedef struct JournalInfoBlock JournalInfoBlock;
...

我把这个问题留着,因为构建过程中出现了太多警告和这个错误,还是让我有点困惑……

更新 II

为了消除关于部署目标的警告,我在编译前编辑了Makefile

$ cat Makefile
...
126 MACOSX_DEPLOYMENT_TARGET=10.3 # => 10.6
...

原始问题

在尝试从源代码构建Python 2.6.4时,我遇到了一个错误:

$ uname -v
$ Darwin Kernel Version 10.2.0: Tue Nov  3 10:37:10 PST 2009; \
    root:xnu-1486.2.11~1/RELEASE_I386

$ cd ~/src/Python-2.6.4
$ ./configure --enable-universalsdk=/ --prefix=$HOME
checking for --with-universal-archs... 32-bit
...
checking machine type as reported by uname -m... i386
...
checking for OSX 10.5 SDK or later... no   // <- But I have XCode + the SDKs installed?
...

$ make
...

...
/usr/include/hfs/hfs_format.h:765: error: \
    expected specifier-qualifier-list before ‘uuid_string_t’

这个错误似乎与Python/mactoolboxglue.c有关。欢迎提供线索!


此外,我还收到了很多这样的警告:

/usr/include/AvailabilityMacros.h:108:14: warning: #warning Building for \
Intel with Mac OS X Deployment Target < 10.4 is invalid.
gcc -c -arch ppc -arch i386 -isysroot /  -fno-strict-aliasing -DNDEBUG -g \
-fwrapv -O3 -Wall -Wstrict-prototypes  -I. -IInclude -I./Include  \
-DPy_BUILD_CORE -o Objects/structseq.o  Objects/structseq.c
In file included from /usr/include/architecture/i386/math.h:626,
             from /usr/include/math.h:28,
             from Include/pyport.h:235,
             from Include/Python.h:58,
             from Objects/structseq.c:4:

2 个回答

1

看起来你并不是唯一遇到这个错误的人:

不确定这是否有相同的根本原因:

http://trac.macports.org/ticket/21282

往下翻到最后的评论,那里的内容似乎表明有个好结果。(为了方便在这里重复一下):

...//来自trac.macports.org的引用:

“试着重命名、移动或删除 /opt/local/include/uuid/uuid.h”

...//引用结束

4

试着在 configure 的参数中加上 --universal-archs=32-bit

补充说明:你可能还需要设置一个环境变量 MACOSX_DEPLOYMENT_TARGET=10.6,并且明确使用 10.6 的 SDK:

export MACOSX_DEPLOYMENT_TARGET=10.6
./configure --universal-archs=32-bit --enable-universalsdk=/Developer/SDKs/MacOSX10.6.sdk ...

在 10.6 上构建 Python 还有一些配置问题。如果你重复使用之前的构建目录,记得把之前运行 configure 时留下的缓存文件清理掉。

顺便说一下,如果你只需要 32 位的版本,可以去 python.org 下载 2.6.4 的 OS X 安装包。

撰写回答