Skip to content

Commit

Permalink
Fix python3.7 linking error on Mac
Browse files Browse the repository at this point in the history
Error:
ld: library not found for -lpython3.7m

Solution
use result of `python-config --ldflags` to get correct link library path, search the flags starts with "-L"

#51
  • Loading branch information
Falldog committed Apr 26, 2019
1 parent 9aba80c commit 847ab11
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import imp
import hashlib
import sysconfig
import subprocess
from os.path import join
from distutils.core import setup, Extension, Command
from distutils.dist import Distribution
Expand Down Expand Up @@ -66,6 +67,10 @@ def is_msvc():
return sys.platform == 'win32' and not is_mingw()


def is_mac():
return sys.platform == 'darwin'


def hash_key(key):
if PY2:
factor = sum([ord(s) for s in key])
Expand Down Expand Up @@ -334,6 +339,13 @@ def get_exe_link_args():
if is_msvc() and (ver == '3.3' or ver == '3.4'):
# For Fix Manifest error, https://bugs.python.org/issue4431
return ['/MANIFEST']

# add -Lxxxx for link correct lib -lpython3.x
if is_mac():
ldflags = subprocess.check_output('python{ver}-config --ldflags'.format(ver=ver), shell=True)
ldflags = ldflags.decode('utf8')
return [ld for ld in ldflags.split() if ld.startswith('-L')]

return None


Expand Down

0 comments on commit 847ab11

Please sign in to comment.