如何重新分发wxHaskell应用程序?

esa*_*981 5 haskell wxhaskell

我正在使用ghc 7.6.3.我从这里安装了wxHaskell:https://github.com/wxHaskell/wxHaskell

它工作,示例程序编译和运行成功.

现在唯一的问题是我想在mac OS X上分发一个wxHaskell应用程序.我尝试使用macosx-app和cabal-macosx(https://github.com/michaelt/cabal-macosx)制作一个"app"文件.它在我的机器上运行正常,但无法在另一台计算机上运行.我收到以下错误:

Dyld Error Message: Library not loaded: /Users/user/.cabal/lib/wxc-0.90.1.0/ghc-7.6.3/libwxc.dylib.
Run Code Online (Sandbox Code Playgroud)

我使用的是OS X 10.8.4(Mountain Lion),但我也有兴趣在Windows上编译应用程序并重新分发它们.

什么是重新分发wxHaskell应用程序的最佳方法?

Setup.hs

-- Example Setup.hs for the wxHello app.

import Distribution.MacOSX
import Distribution.Simple

main :: IO ()
main = defaultMainWithHooks $ simpleUserHooks {
         postBuild = appBundleBuildHook guiApps -- no-op if not MacOS X
       }

guiApps :: [MacApp]
guiApps = [MacApp "WxHello"
                  (Just "resources/WxHello.icns")
                  Nothing -- Build a default Info.plist for the icon.
                  [] -- No other resources.
                  [] -- No other binaries.
                  ChaseWithDefaults -- Try changing to ChaseWithDefaults
          ]
Run Code Online (Sandbox Code Playgroud)

wxHello.cabal:

Name:                   wxHello
Version:                0.1.0
Stability:              Alpha
Synopsis:               wxWidgets `Hello World' example for cabal-macosx
Description:
    Example showing how to use cabal-macosx to build an application
    bundle for a simple `Hello World' program using the wxWidgets GUI
    toolkit.
Category:               Data
License:                BSD3
License-file:           LICENSE
Copyright:              Andy Gimblett <haskell@gimbo.org.uk>
Author:                 Andy Gimblett <haskell@gimbo.org.uk>
Maintainer:             Andy Gimblett <haskell@gimbo.org.uk>
Build-Type:             Custom
Cabal-Version:          >=1.6

Executable WxHello
  hs-source-dirs:       src
  Main-is:              Main.hs
  Build-Depends:        base >= 3 && < 5, cabal-macosx, wx
  ghc-options:          -fwarn-tabs -threaded -Wall
Run Code Online (Sandbox Code Playgroud)

以下是生成的包中的dylib文件:

WxHello.app $ find . | grep dylib
./Contents/Frameworks/Users/user/.cabal/lib/wxc-0.90.1.0/ghc-7.6.3/libwxc.dylib
./Contents/Frameworks/Users/user/temp/wxWidgets-2.9.5/build-release/lib/libwx_baseu-2.9.5.0.0.dylib
./Contents/Frameworks/Users/user/temp/wxWidgets-2.9.5/build-release/lib/libwx_baseu_net-2.9.5.0.0.dylib
./Contents/Frameworks/Users/user/temp/wxWidgets-2.9.5/build-release/lib/libwx_baseu_xml-2.9.5.0.0.dylib
./Contents/Frameworks/Users/user/temp/wxWidgets-2.9.5/build-release/lib/libwx_osx_cocoau_adv-2.9.5.0.0.dylib
./Contents/Frameworks/Users/user/temp/wxWidgets-2.9.5/build-release/lib/libwx_osx_cocoau_aui-2.9.5.0.0.dylib
./Contents/Frameworks/Users/user/temp/wxWidgets-2.9.5/build-release/lib/libwx_osx_cocoau_core-2.9.5.0.0.dylib
./Contents/Frameworks/Users/user/temp/wxWidgets-2.9.5/build-release/lib/libwx_osx_cocoau_gl-2.9.5.0.0.dylib
./Contents/Frameworks/Users/user/temp/wxWidgets-2.9.5/build-release/lib/libwx_osx_cocoau_html-2.9.5.0.0.dylib
./Contents/Frameworks/Users/user/temp/wxWidgets-2.9.5/build-release/lib/libwx_osx_cocoau_propgrid-2.9.5.0.0.dylib
./Contents/Frameworks/Users/user/temp/wxWidgets-2.9.5/build-release/lib/libwx_osx_cocoau_qa-2.9.5.0.0.dylib
./Contents/Frameworks/Users/user/temp/wxWidgets-2.9.5/build-release/lib/libwx_osx_cocoau_ribbon-2.9.5.0.0.dylib
./Contents/Frameworks/Users/user/temp/wxWidgets-2.9.5/build-release/lib/libwx_osx_cocoau_richtext-2.9.5.0.0.dylib
./Contents/Frameworks/Users/user/temp/wxWidgets-2.9.5/build-release/lib/libwx_osx_cocoau_stc-2.9.5.0.0.dylib
./Contents/Frameworks/Users/user/temp/wxWidgets-2.9.5/build-release/lib/libwx_osx_cocoau_webview-2.9.5.0.0.dylib
./Contents/Frameworks/Users/user/temp/wxWidgets-2.9.5/build-release/lib/libwx_osx_cocoau_xrc-2.9.5.0.0.dylib
./Contents/Frameworks/usr/lib/libc++abi.dylib
./Contents/Frameworks/usr/lib/libexpat.1.dylib
./Contents/Frameworks/usr/lib/libiconv.2.dylib
./Contents/Frameworks/usr/lib/libstdc++.6.dylib
./Contents/Frameworks/usr/lib/libz.1.dylib
Run Code Online (Sandbox Code Playgroud)

Lev*_*son 0

包含您的 .cabal 和 Setup.hs 文件可能会有所帮助。

从 cabal-macosx 的文档来看,您似乎需要确保 Setup.hs 中的 MacApp 数据值获得适合ChaseDeps的模式(使用ChaseWithDefaults而不是DoNotChase),以便构建可再发行的应用程序包。

如果您已经这样做了,但仍然遇到相同的错误,我会检查生成的应用程序包,看看是否复制了必要的库。您可能会找到足够的信息来向 cabal-macosx 维护者提交错误。

编辑

根据您所包含的内容,设置看起来是正确的,并且似乎至少复制了库依赖项。我认为问题可能出在 cabal-macosx 包上。

查看依赖项修复代码的源代码,看起来它应该"Updating <library>'s dependence on <path> to <path>"在构建捆绑包时打印一堆行。你看到那些了吗?是否有任何行更新二进制文件本身?

我对 OS X 链接过程不是很有经验,但我认为除非在复制库链接二进制文件,否则它也需要更新。您应该能够使用/usr/bin/otool -L <filename>/usr/bin/install_name_tool手动修复安装过程中可能丢失的二进制文件中的路径。

以下是这两个工具的手册页:

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/install_name_tool.1.html

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/otool.1.html