如何在“OS X Framework-build python”中与libpython建立静态链接

sta*_*tOL 5 c++ python macos gcc g++

libpython2.7我正在尝试与on建立静态链接Mac OS X 10.11

虽然静态链接可以成功地与libpython2.7.ain 一起使用pyenv(anaconda)-build python,但它不能与libpython2.7.ain 一起使用Framework-build python

创建静态 Mac OS XC 版本

由于该-static选项似乎不适用于 Mac OS X,因此我尝试了以下方法。

CXXFLAGS=-I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
LIBS=/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/libpython2.7.a

$ g++ -o main main.cc $(CXXFLAGS) $(LIBS)
Run Code Online (Sandbox Code Playgroud)

并得到以下结果。

$ otool -L main
main:
    /System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.10)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
Run Code Online (Sandbox Code Playgroud)

与 的链接libpython2.7.a导致与 的动态链接Versions/2.7/Python

我还发现 和libpython2.7.a都是libpython2.7.dylib到 的符号链接/System/Library/Frameworks/Python.framework/Versions/2.7/Python

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/libpython2.7.dylib
-> ../../../Python

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/libpython2.7.a
-> ../../../Python
Run Code Online (Sandbox Code Playgroud)
  1. libpython2.7为什么in不存在有效的静态库Framework-build python

  2. /System/Library/Frameworks/Python.framework/Versions/2.7/Python和标准共享库有什么区别?

  3. 如何与libpython2.7in建立静态链接Framework-build python