How to link to a specific framework version in Xco

2019-03-28 06:27发布

I've got an application that links against OS X's Python.framework. Since Snow Leopard has upgraded to Python 2.6, the framework now contains versions for 2.4, 2.5, and 2.6. My program doesn't seem to want to link against 2.6, though, and this ends up causing errors when I try and use features from the newer Python runtime.

I know I can just use install_name_tool to change the linking in a post-build step, but is there any way to simply tell it where to link during the build? Seems like a pretty common use case.

2条回答
我想做一个坏孩纸
2楼-- · 2019-03-28 06:44

I had this specific problem, too, and couldnt find a way to get Python Framework 2.6 in the build.

I couldn't get the OTHER_LINKER_FLAGS approach to work, alas.

So, like SJML suggested, I used a post build step like so:

#
# Force the required version of Python to be 2.6
# dvb10.12.01

install_name_tool \
    -change \
        /System/Library/Frameworks/Python.framework/Versions/2.5/Python \
        /System/Library/Frameworks/Python.framework/Versions/2.6/Python \
    $TARGET_BUILD_DIR/omino_python.plugin/Contents/MacOS/omino_python

Just putting it out there for the grepping. :)

查看更多
Evening l夕情丶
3楼-- · 2019-03-28 06:48

I have not tried this, but I believe it will work.

1) Do NOT add the framework to your Xcode project

2) Instead, use the full path to the library in "OTHER_LINKER_FLAGS" - so "/System/Library/Frameworks/Python.framework/2.5/Python"

3) You'll also want to set the framework search path to "/System/Library/Frameworks/Python.framework/2.5/" and set the include search path to "/System/Library/Frameworks/Python.framework/2.5/Headers"

However, with all that said, it will leave you vulnerable to any changes Apple may make. For example, everything will break if they later remove 2.5 from the framework. It'd be a much better idea to just update your app to work with the current version of Python.

查看更多
登录 后发表回答