2012-10-29 60 views
4

我想用opencv和pygame构建一个应用程序。这两个库已经安装了macports。我也在macports python中安装了py2app。 我运行一个简单的py2app脚本py2app error for opencv/macports app。如何使用headerpad_max_install_names标志编译opencv?

from setuptools import setup 

setup(
    app = [ 
     '/full/path/to/my_script.py', 
    ], 
    options={ 
     "py2app":{ 
      'argv_emulation': True, 
     } 
    }, 
    setup_requires=['py2app'] 
) 

不幸的是,py2app失败,出现以下错误:“ValueError异常:新的Mach-O头太大搬迁”

是否有可能使一个应用程序捆绑与opencv和macports?

感谢您的帮助

更新:

这里是ronaldoussoren的答案伍兹霍尔海洋研究所是py2app developper:

Shared libraries on OSX contain an absolute path to their location, and likewise all used libraries are also mentioned using an absolute path. Py2app uses macholib to rewrite those mentions to relative paths starting with '@executable_path'. For libraries that are located in /opt/local the new path requires more space than the old one, hence the error message. One way to ensure that there is enough space is the linker flag "headerpad_max_install_names". I don't know how to tell darwinports to add this flag when building opencv.

还请注意,我有一个类似的问题与pyinstaller。

我试图修改opencv Portfile没有任何改变。我真的不知道该添加此链接器标志的位置。

任何想法如何解决它?

更新:这是我的Portfile

# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4 
# $Id: Portfile 99165 2012-10-28 22:56:03Z [email protected] $ 

PortSystem      1.0 
PortGroup      cmake 1.0 

name       opencv 
version       2.4.2 
revision      2 
categories      graphics science 
license       BSD 
platforms      darwin 
maintainers      nomaintainer 

description      Intel(R) Open Source Computer Vision Library 

long_description    opencv is a library that is mainly aimed at real time \ 
           computer vision. Some example areas would be \ 
           Human-Computer Interaction (HCI), Object Identification, \ 
           Segmentation and Recognition, Face Recognition, Gesture \ 
           Recognition, Motion Tracking, Ego Motion, Motion \ 
           Understanding, Structure From Motion (SFM), and Mobile \ 
           Robotics. 

homepage      http://opencv.willowgarage.com/wiki/ 
master_sites     sourceforge:project/opencvlibrary/opencv-unix/${version} 
use_bzip2      yes 
distname      OpenCV-${version} 

checksums      rmd160 496964503629b0ff4432fbdd276837ab3f134411 \ 
           sha256 690023811e03e21df996291392fcf78e43e42ef557b9307503c74c74b4272c28 

depends_build-append   port:pkgconfig 

depends_lib-append    port:zlib \ 
           path:lib/libavcodec.dylib:ffmpeg \ 
           port:libpng \ 
           port:tiff \ 
           port:jasper \ 
           port:jpeg \ 
           port:bzip2 \ 
           port:openexr \ 
           port:ilmbase \ 
           port:eigen3 

patchfiles      patch-fix_dirname_case.diff \ 
           patch-install_name.diff 

configure.args-append   -DBUILD_NEW_PYTHON_SUPPORT=OFF \ 
           -DBUILD_EXAMPLES=ON \ 
           -DINSTALL_C_EXAMPLES=ON \ 
           -DBZIP2_LIBRARIES=${prefix}/lib/libbz2.dylib \ 
           -DZLIB_LIBRARY=${prefix}/lib/libz.dylib \ 
           -DWITH_OPENEXR=ON \ 
           -DWITH_1394=OFF \ 
           -DWITH_EIGEN=ON \ 
           -DEIGEN_INCLUDE_PATH=${prefix}/include/eigen3 \ 
           -DBUILD_JASPER=OFF \ 
           -DBUILD_JPEG=OFF \ 
           -DBUILD_PNG=OFF \ 
           -DBUILD_TIFF=OFF \ 
           -DBUILD_ZLIB=OFF 
configure.ldflags-append  "-Wl,-headerpad_max_install_names" 

# gcc-4.0 exits with a bus error 
if {${configure.compiler} == "gcc-4.0"} { 
    configure.compiler gcc-4.2 
    if {![file executable ${configure.cc}]} { 
     depends_build-append port:apple-gcc42 
     depends_skip_archcheck-append apple-gcc42 
     configure.compiler apple-gcc-4.2 
    } 
} 

platform darwin { 
    if {${os.major} <= 9} { 
     # Video Decode Acceleration Framework is not available 
     patchfiles-append  patch-highgui_CMakeLists.txt.diff 
    } 
} 

post-destroot { 
    xinstall -d ${destroot}${prefix}/lib/cmake 
    move ${destroot}${prefix}/share/OpenCV/OpenCVConfig-version.cmake \ 
     ${destroot}${prefix}/share/OpenCV/OpenCVConfig.cmake \ 
     ${destroot}${prefix}/lib/cmake/ 
} 

variant dc1394 description {Use libdc1394 for FireWire camera. Breaks compatibility with Apple iSight FireWire camera.} { 
    depends_lib-append   port:libdc1394 
    configure.args-delete  -DWITH_1394=OFF 
    configure.args-append  -DWITH_1394=ON \ 
           -DHAVE_1394=ON 
} 

variant qt4 description {Use qt4 backend for graphical interface.} { 
    PortGroup     qt4 1.0 
    configure.args-append  -DWITH_QT=ON 
} 

variant python26 conflicts python27 description {Add Python 2.6 bindings} { 
    depends_lib-append   port:python26 \ 
           port:py26-numpy 
    configure.args-delete  -DBUILD_NEW_PYTHON_SUPPORT=OFF 
    configure.args-append  -DINSTALL_PYTHON_EXAMPLES=ON \ 
           -DBUILD_NEW_PYTHON_SUPPORT=ON \ 
           -DPYTHON_EXECUTABLE=${prefix}/bin/python2.6 \ 
           -DPYTHON_LIBRARY=${prefix}/lib/libpython2.6.dylib \ 
           -DPYTHON_INCLUDE_DIR=${frameworks_dir}/Python.framework/Versions/2.6/Headers \ 
           -DPYTHON_PACKAGES_PATH=${frameworks_dir}/Python.framework/Versions/2.6/lib/python2.6/site-packages 
} 

variant python27 conflicts python26 description {Add Python 2.7 bindings} { 
    depends_lib-append   port:python27 \ 
           port:py27-numpy 
    configure.args-delete  -DBUILD_NEW_PYTHON_SUPPORT=OFF 
    configure.args-append  -DINSTALL_PYTHON_EXAMPLES=ON \ 
           -DBUILD_NEW_PYTHON_SUPPORT=ON \ 
           -DPYTHON_EXECUTABLE=${prefix}/bin/python2.7 \ 
           -DPYTHON_LIBRARY=${prefix}/lib/libpython2.7.dylib \ 
           -DPYTHON_INCLUDE_DIR=${frameworks_dir}/Python.framework/Versions/2.7/Headers \ 
           -DPYTHON_PACKAGES_PATH=${frameworks_dir}/Python.framework/Versions/2.7/lib/python2.7/site-packages 
    configure.ldflags-append "-Wl,-headerpad_max_install_names" 
} 

variant tbb description {Use Intel TBB} { 
    depends_lib-append   port:tbb 
    configure.args-append  -DWITH_TBB=ON \ 
           -DHAVE_TBB=ON \ 
           -DTBB_INCLUDE_DIRS=${prefix}/include \ 
           -DOPENCV_LINKER_LIBS="-ltbb -ltbbmalloc" 
} 

livecheck.type     sourceforge 
livecheck.name     opencvlibrary 
livecheck.regex     /OpenCV-(\[0-9a-z.\]+)${extract.suffix} 

更新:macport团队制作的问题,但不幸的是他们的修复并没有解决我的问题。见http://trac.macports.org/ticket/36841

+0

请提供关于所提供的答案的一些反馈,如果它不为你工作。 – Vortexfive

+0

对不起,我没有时间测试它。其他一些热土豆。 :)我会尽快给出反馈。 – luc

+0

您是试图为您的系统创建一个可再发行组件包还是一个启动器?在后一种情况下,您可以使用_-A_ py2app选项来别名库,例如'python setup.py py2app -A' – anddam

回答

4

您需要在OpenCV的Portfile添加

configure.ldflags-append "-Wl,-headerpad_max_install_names"

附近的某处configure.args-append线。 (Documentation

我希望这可以解决您的问题。否则,你可能不得不使用该标志编译OpenCV的所有依赖关系,这可能是很多工作。如果出现这种情况,您可能需要查看https://trac.macports.org/ticket/29838,并且您希望默认情况下启用headerpad_max_install_names标志。

如果您希望您的Portfile的更改保留下来,并且不会在下次更新OpenCV时撤消,您可以按照Sneaky patching source with Macports的说明操作。但是,这会阻止OpenCV的更新被自动安装!

+0

不幸的是,configure.ldflags-append“-Wl,-headerpad_max_install_names”不能解决问题。无论如何,+1和很多谢谢你的回答 – luc

+0

@luc:好的,很抱歉听到这个消息。我只想指出,如果不使用tbb变体,'configure.ldflags-append“-Wl,-headerpad_max_install_names”应该位于'variant tbb description {Use Intel TBB} {...}'块之外(请参阅问题中的Portfile)。 – Vortexfive

+0

我再次修改了Portfile(我也在问题中更新了它),但仍然有同样的错误。感谢您的帮助(它值得奖励:) – luc

1

昨天我从py2app开发人员的指导中找到了一个解决方案。

首先,知道-Xlinker,-Wl和。 -headpad ...标志没有解决我的问题,尽管我仍将它们保存在macports.conf中。对我来说,关键是增加macports文件深度并减少构建目录文件深度。具体来说,我使用--prefix =/opt/localdepth/localdepth/localdepth/localdepth/local来安装macports,并且构建在/ opt/build中。现在py2app成功运行。

参见: https://bitbucket.org/ronaldoussoren/py2app/issue/93/mach-o-header-may-be-too-large-to-relocate https://trac.macports.org/ticket/38163