我正在尝试编译SciPy,使其能够在32位和64位架构上运行。因为某些使用该库的应用程序只支持其中一种架构。我遵循了几篇 SO 问题中的建议。这个命令对我之前类似的构建起作用过,但现在似乎一些已编译的共享库只针对x86_64。
sudo ARCHFLAGS="-arch i386 -arch x86_64" pip install scipy
sudo
之前设置环境变量,将-m32 -m64
放入FFlags中,使用OSX命令行工具、完整的Xcode安装、使用clang代替OSX自带的LLVM,按照官方SciPy安装说明进行操作,使用easy_install而不是pip,甚至单独进行./configure等,但似乎无法使其正常工作。奇怪的是,一些.so文件可以构建两种架构,但有些则不能:dhcp-10-249-71-202:~ kastman$ file /Library/Python/2.7/site-packages/scipy/optimize/*.so
/Library/Python/2.7/site-packages/scipy/optimize/_cobyla.so: Mach-O 64-bit bundle x86_64
/Library/Python/2.7/site-packages/scipy/optimize/_lbfgsb.so: Mach-O 64-bit bundle x86_64
/Library/Python/2.7/site-packages/scipy/optimize/_minpack.so: Mach-O 64-bit bundle x86_64
/Library/Python/2.7/site-packages/scipy/optimize/_nnls.so: Mach-O 64-bit bundle x86_64
/Library/Python/2.7/site-packages/scipy/optimize/_slsqp.so: Mach-O 64-bit bundle x86_64
/Library/Python/2.7/site-packages/scipy/optimize/_zeros.so: Mach-O universal binary with 2 architectures
/Library/Python/2.7/site-packages/scipy/optimize/_zeros.so (for architecture i386): Mach-O bundle i386
/Library/Python/2.7/site-packages/scipy/optimize/_zeros.so (for architecture x86_64): Mach-O 64-bit bundle x86_64
/Library/Python/2.7/site-packages/scipy/optimize/minpack2.so: Mach-O 64-bit bundle x86_64
/Library/Python/2.7/site-packages/scipy/optimize/moduleTNC.so: Mach-O universal binary with 2 architectures
/Library/Python/2.7/site-packages/scipy/optimize/moduleTNC.so (for architecture i386): Mach-O bundle i386
/Library/Python/2.7/site-packages/scipy/optimize/moduleTNC.so (for architecture x86_64): Mach-O 64-bit bundle x86_64
从编译日志来看,似乎已成功传递参数给那些正常工作和不正常工作的库:
# Minpack doesn't build fat binaries
/usr/local/bin/gfortran -Wall -Wall -undefined dynamic_lookup -bundle build/temp.macosx-10.7-intel-2.7/build/src.macosx-10.7-intel-2.7/scipy/optimize/minpack2/minpack2module.o build/temp.macosx-10.7-intel-2.7/build/src.macosx-10.7-intel-2.7/fortranobject.o build/temp.macosx-10.7-intel-2.7/scipy/optimize/minpack2/dcsrch.o build/temp.macosx-10.7-intel-2.7/scipy/optimize/minpack2/dcstep.o -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin11/4.6.2 -Lbuild/temp.macosx-10.7-intel-2.7 -lgfortran -o build/lib.macosx-10.7-intel-2.7/scipy/optimize/minpack2.so
building 'scipy.optimize._slsqp' extension
compiling C sources
C compiler: clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe
#... but moduleTNC does.
llvm-gcc-4.2 -Wl,-F. -bundle -undefined dynamic_lookup -Wl,-F. -arch i386 -arch x86_64 build/temp.macosx-10.7-intel-2.7/scipy/optimize/tnc/moduleTNC.o build/temp.macosx-10.7-intel-2.7/scipy/optimize/tnc/tnc.o -Lbuild/temp.macosx-10.7-intel-2.7 -o build/lib.macosx-10.7-intel-2.7/scipy/optimize/moduleTNC.so
building 'scipy.optimize._cobyla' extension
compiling C sources
C compiler: clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe
有可能是我使用的gfortran编译器的差异吗?我使用了brew install gfortran
,这在SciPy文档中应该很好。我认为重要的一行应该是C编译器:clang,它看起来几乎相同,包括两个-arch。
我尝试过的最详细的构建是:
sudo env ARCHFLAGS="-arch i386 -arch x86_64" ARCH="i386 x86_64" CC="clang" CXX="clang" FFLAGS="-ff2c -m32 -m64" pip install scipy
有人有关于如何进一步诊断这个问题的建议吗?
(OSX 10.7,最近的MacBookPro,使用CLI工具和Xcode从gcc编译)