This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Problems building pyhton from source on Snow Leopard (Mac OS X 10.6)
Type: compile error Stage: resolved
Components: Installation, macOS Versions: Python 3.1
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ronaldoussoren Nosy List: FredrikHedman, ronaldoussoren
Priority: normal Keywords:

Created on 2009-10-11 11:16 by FredrikHedman, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg93851 - (view) Author: Fredrik Hedman (FredrikHedman) Date: 2009-10-11 11:16
-*- mode: outline -*-

* Problems building pyhton from source on Snow Leopard (Mac OS X 10.6)
  1 error and 39 warnings and a quick fix.
** Building python from source with --enable-framework
I have a fresh install of Snow Leopard and the accompanying Xcode 3.2;
see below for platform details. I'm trying to build python from
Python-3.1.1.tar.bz2. The build

   $ export MACOSX_DEPLOYMENT_TARGET=10.6
   $ ./configure  --enable-framework
   $ make

fails with the following error:

   gcc  -framework CoreFoundation Python.framework/Versions/3.1/Python -
o python \
			   Modules/python.o \
			   Python.framework/Versions/3.1/Python -ldl
   ld: warning: in Python.framework/Versions/3.1/Python, file is not of 
required architecture
   ld: warning: in Python.framework/Versions/3.1/Python, file is not of 
required architecture
   Undefined symbols:
     "_PyMem_Malloc", referenced from:
	 _main in python.o
	 _main in python.o
	 _main in python.o
	 _main in python.o
     "_Py_Main", referenced from:
	 _main in python.o
	 _main in python.o
     "_PyMem_Free", referenced from:
	 _main in python.o
	 _main in python.o
	 _main in python.o
	 _main in python.o
   ld: symbol(s) not found
   collect2: ld returned 1 exit status
   make: *** [python] Error 1

** Error analysis and quick fix
The symbols above that are not defined are all defined in the library 
built
before the error occurs: libpython3.1.a. For some reason configure
does not include this library when linking.

Looking at the generated Makefile and the rule BUILDPYTHON one sees
that BLDLIBRARY seems to be not set properly.  If I tweak the Makefile 
and set

   BLDLIBRARY=     -L. $(LIBRARY)

then relaunching make works just fine.  The failed rule above
completes just fine and make completes without error.  

** 39 warnings and "file is not of required architecture"?
The results are not flawless since there are some complaints:

   Python build finished, but the necessary bits to build these modules 
were not found:
   ossaudiodev        spwd
   To find the necessary bits, look in setup.py in detect_modules() for 
the module's name.

   Failed to build these modules:
   _curses            _curses_panel

I choose to ignore these missing bits along with the other 39 warnings
generated during the build.  Most seem to be about quality of code.
The most worrying is the one about

   ld: warning: in Python.framework/Versions/3.1/Python, file is not of 
required architecture

which I do not really understand at this point, being quite new to
Cocoa and frameworks.

** Testing
make test reports:

    test_zlib
    310 tests OK.
    1 test failed:
	test_telnetlib
    24 tests skipped:
	test_codecmaps_cn test_codecmaps_hk test_codecmaps_jp
	test_codecmaps_kr test_codecmaps_tw test_curses test_epoll
	test_largefile test_nis test_normalization test_ossaudiodev
	test_pep277 test_smtpnet test_socketserver test_startfile
	test_timeout test_tk test_ttk_guionly test_urllib2net
	test_urllibnet test_winreg test_winsound test_xmlrpc_net
	test_zipfile64
    Those skips are all expected on darwin.

So the quick fix should be acceptable.

* A more permanent fix?  Needs verification
In file configure.in change (line 674)
      BLDLIBRARY=''
to
      BLDLIBRARY='-L. -lpython$(VERSION)'

Then generate a new configure script with

    autoreconf
    ./configure MACOSX_DEPLOYMENT_TARGET=10.6 --enable-framework
    make && make test

This seems to work fine, but must to be verified by someone with more
Cocoa and Framework knowledge since it sort of goes against the comments
that precede the changed line in configure.in.

* Platform
   $ uname -a
   Darwin beech.local 10.0.0 Darwin Kernel Version 10.0.0: Fri Jul 31 
22:47:34 PDT 2009; root:xnu-1456.1.25~1/RELEASE_I386 i386
   $ xcode-select -version
   xcode-select version 895.
msg93852 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2009-10-11 11:36
Fredrik: OSX 10.6 was released after Python 3.1.1. I know that we had to 
apply a number of patches to the 2.6 branch to get that to compile 
properly on 10.6, and those should have been forward ported to the 3.1 
branch.

Could you please do a checkout of the 3.1 branch and test if that solves 
the issue for you (it does for me)?

One issue you are running into is that the compiler on 10.6 generates 
64-bit code by default, while Python's build system assumes that the 
compiler generates 32-bit code. This was fixed in python 2.6.3 and the 
3.x branches a while back, but hasn't made it into a release of 3.1 yet.
msg93874 - (view) Author: Fredrik Hedman (FredrikHedman) Date: 2009-10-11 20:16
Hi Ronald,

I checked out release31-maint from the python svn.  It compiles fine and passes all the tests.

So if I understand you correctly, these corrections need to be moved into 3.1.1 and that is also
tru for the 32/64-bit compilation issues. 

Cheers,
/Fredrik Hedman

On Sunday, October 11, 2009, at 01:36PM, "Ronald Oussoren" <report@bugs.python.org> wrote:
>
>Ronald Oussoren <ronaldoussoren@mac.com> added the comment:
>
>Fredrik: OSX 10.6 was released after Python 3.1.1. I know that we had to 
>apply a number of patches to the 2.6 branch to get that to compile 
>properly on 10.6, and those should have been forward ported to the 3.1 
>branch.
>
>Could you please do a checkout of the 3.1 branch and test if that solves 
>the issue for you (it does for me)?
>
>One issue you are running into is that the compiler on 10.6 generates 
>64-bit code by default, while Python's build system assumes that the 
>compiler generates 32-bit code. This was fixed in python 2.6.3 and the 
>3.x branches a while back, but hasn't made it into a release of 3.1 yet.
>
>----------
>
>_______________________________________
>Python tracker <report@bugs.python.org>
><http://bugs.python.org/issue7102>
>_______________________________________
>
>
msg94206 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2009-10-18 07:18
The fixes will be in 3.1.2 and 3.2 when those are released. I don't know 
when that it though, until than you can build the version in the 
repository.

The 3.1 branch tends to be stable, developers are supposed to only port 
bugfixes to this branch, new development goes into 3.2.
History
Date User Action Args
2022-04-11 14:56:53adminsetgithub: 51351
2009-10-18 07:18:29ronaldoussorensetstatus: open -> closed
resolution: fixed
messages: + msg94206

stage: resolved
2009-10-11 20:16:39FredrikHedmansetmessages: + msg93874
title: Problems building pyhton from source on Snow Leopard (Mac OS X 10.6) -> Problems building pyhton from source on Snow Leopard (Mac OS X 10.6)
2009-10-11 11:36:41ronaldoussorensetmessages: + msg93852
2009-10-11 11:16:05FredrikHedmancreate