Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More flexible dynamic linking for python module on OS X #453

Closed
artemp opened this issue Oct 11, 2011 · 5 comments
Closed

More flexible dynamic linking for python module on OS X #453

artemp opened this issue Oct 11, 2011 · 5 comments

Comments

@artemp
Copy link
Member

artemp commented Oct 11, 2011

Currently both boost_python and the mapnik python module directly link to the Python Framework/dylib, which can be restrictive. A python module is loaded by Python, thus all of the necessary Python symbols are loaded. Linking Python directly may not be standard for OS X, and instead other modules use (pycairo for example) the flag to ld of 'undefined dynamic_lookup'. Thus when any major.minor version of Python should work with a mapnik module compiled against that major version by loading in any other binary of the same major.minor version (though there could be be some differences in the Python build that could cause trouble).

This could allow mapnik's python module to be used with either the /System (apple installed) or /Library (python.org installed) python versions as long as the major.minor version matches. And this would potentially avoid the all to common:

 'Fatal Python error: Interpreter not initialized (version mismatch?)'
Abort trap
@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[springmeyer] Getting boost python to not link directly to a python module can be done by:

Index: tools/build/v2/tools/python.jam
===================================================================
--- tools/build/v2/tools/python.jam (revision 57846)
+++ tools/build/v2/tools/python.jam (working copy)
@@ -976,7 +976,7 @@
     # the Python framework, even when building extensions. Note that framework
     # builds of Python always use shared libraries, so we do not need to worry
     # about duplicate Python symbols.
-    if $(target-os) in windows cygwin darwin
+    if $(target-os) in windows cygwin
     {
         alias python_for_extensions : python : $(target-requirements) ;
     }
Index: tools/build/v2/tools/darwin.jam
===================================================================
--- tools/build/v2/tools/darwin.jam (revision 57846)
+++ tools/build/v2/tools/darwin.jam (working copy)
@@ -465,7 +465,7 @@
 }

 # Set the max header padding to allow renaming of libs for installation.
-flags darwin.link.dll OPTIONS : -headerpad_max_install_names ;
+flags darwin.link.dll OPTIONS : -headerpad_max_install_names -undefined dynamic_lookup ;

 # To link the static runtime we need to link to all the core runtime libraries.
 flags darwin.link OPTIONS <runtime-link>static

@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[springmeyer] and with mapnik:

Index: bindings/python/SConscript
===================================================================
--- bindings/python/SConscript  (revision 1389)
+++ bindings/python/SConscript  (working copy)
@@ -40,10 +40,11 @@
         libraries.append('boost_thread%s' % env['BOOST_APPEND'])
     if '-DHAVE_CAIRO' in env['CXXFLAGS']:
         libraries.append([lib for lib in env['LIBS'] if lib.startswith('cairo')])
-    if env['FRAMEWORK_PYTHON']:
-        linkflags = '-F%s -framework Python' % env['FRAMEWORK_SEARCH_PATH']
-    else:
-        linkflags = '-lpython%s' % env['PYTHON_VERSION']
+    #if env['FRAMEWORK_PYTHON']:
+    #    linkflags = '-F%s -framework Python' % env['FRAMEWORK_SEARCH_PATH']
+    #else:
+    #    linkflags = '-lpython%s' % env['PYTHON_VERSION']
+    linkflags = '-undefined dynamic_lookup'

 headers = [env['PYTHON_INCLUDES']] + env['CPPPATH']

@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[springmeyer] option added to allow this to be controlled during mapnik build in r1779.

leaving open for now to consider boost issue (and perhaps supplying patch to boost.python developers in future).

@springmeyer
Copy link
Member

not motivated to change this in boost at this time (been patching when I need it). closing.

@springmeyer
Copy link
Member

someone else ended up filing this against boost: https://svn.boost.org/trac/boost/ticket/3930

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants