Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Initial Questions</h2> <blockquote> <p>Should this work with ghci? If so, what am I doing wrong or how can I fix the crash?</p> </blockquote> <p>On OSX 10.6.7 (using the Haskell Platform /w GHC 7.0.2) I could load your built shared lib into ghci as follows:</p> <pre><code>➜ GLFW-b git:(master) ✗ ghci dist/build/Graphics/UI/GLFW.hs -Lbuild/dynam ic -lglfw GHCi, version 7.0.2: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading package ffi-1.0 ... linking ... done. Loading object (dynamic) glfw ... done final link ... done [1 of 1] Compiling Graphics.UI.GLFW ( dist/build/Graphics/UI/GLFW.hs, inte rpreted ) Ok, modules loaded: Graphics.UI.GLFW. *Graphics.UI.GLFW&gt; initialize True </code></pre> <p>Note: I built the <code>glfw</code> libs using your provided <code>Makefile</code>, and additionally used your <code>.cabal</code> file to process <code>src/Graphics/UI/GLFW.hsc</code> and build <code>dist/build/Graphics/UI/GLFW.hs</code> (i.e. I'd previously run <code>cabal configure/build</code>).</p> <blockquote> <p>Can I just get by with the static .a version of the library with ghci?</p> </blockquote> <p>Yes, support for loading static libs was included in GHC 7.0.2 (<a href="http://www.haskell.org/ghc/docs/7.0.2/html/users_guide/release-7-0-2.html#id417924">GHC Manual</a>). <code>compiler/ghci/Linker.lhs</code> is a great read, and will give you a high-level sense of how ghci decides what to make of the command line arguments passed to it. Additionally, when navigating various platform support issues, I've found <a href="http://hackage.haskell.org/trac/ghc/wiki/SharedLibraries/PlatformSupport?redirectedfrom=DynamicLinking">this documentation</a> exceedingly useful.</p> <h2>Linking static archives with ghci.</h2> <p>As of writing, line <code>1113</code> of <code>compiler/ghci/Linker.hs</code> demonstrates that <code>ghci</code> currently requires that static archives be built by the package system (i.e. named <code>HSlibname.a</code>)</p> <pre><code>locateOneObj :: [FilePath] -&gt; String -&gt; IO LibrarySpec locateOneObj dirs lib | not ("HS" `isPrefixOf` lib) -- For non-Haskell libraries (e.g. gmp, iconv) we assume dynamic library = assumeDll | not isDynamicGhcLib -- When the GHC package was not compiled as dynamic library -- (=DYNAMIC not set), we search for .o libraries or, if they -- don't exist, .a libraries. = findObject `orElse` findArchive `orElse` assumeDll </code></pre> <p>Further investigation of cmd line argument parsing indicates that libraries specified are collected at line <code>402</code> in the <code>reallyInitDynLinker</code> function:</p> <pre><code>; classified_ld_inputs &lt;- mapM classifyLdInput cmdline_ld_inputs </code></pre> <p>where <code>classifyLdInput</code> is defined over </p> <pre><code>classifyLdInput :: FilePath -&gt; IO (Maybe LibrarySpec) classifyLdInput f | isObjectFilename f = return (Just (Object f)) | isDynLibFilename f = return (Just (DLLPath f)) | otherwise = do hPutStrLn stderr ("Warning: ignoring unrecognised input `" ++ f ++ "'") return Nothing </code></pre> <p>This means that outside of a package specification, there currently is <strong>no direct way to link an archive file in ghci</strong> (or said differently, there currently is no cmd-line argument to do so).</p> <h2>Fixing your cabal package</h2> <p>In your <code>.cabal</code> package specification, you are attempting to build <strong>two</strong> conflicting libraries:</p> <ul> <li><strong>A</strong>: link in a pre-built library (built according to your specification in <code>Setup.hs</code> and <code>Makefile</code>, and linked as per the <code>extra-libraries</code> and <code>extra-lib-dirs</code> directives)</li> <li><strong>B</strong>: build a new library inline (the <code>c-sources</code> and <code>frameworks</code> directives).</li> </ul> <p>A simple fix for the error above is to simply remove all directives enabling <strong>B</strong> when building for Mac OSX, as follows:</p> <pre><code> include-dirs: glfw/include glfw/lib - c-sources: - glfw/lib/enable.c - glfw/lib/fullscreen.c - glfw/lib/glext.c - glfw/lib/image.c - glfw/lib/init.c - glfw/lib/input.c - glfw/lib/joystick.c - glfw/lib/stream.c - glfw/lib/tga.c - glfw/lib/thread.c - glfw/lib/time.c - glfw/lib/window.c + + if !os(darwin) + c-sources: + glfw/lib/enable.c + glfw/lib/fullscreen.c + glfw/lib/glext.c + glfw/lib/image.c + glfw/lib/init.c + glfw/lib/input.c + glfw/lib/joystick.c + glfw/lib/stream.c + glfw/lib/tga.c + glfw/lib/thread.c + glfw/lib/time.c + glfw/lib/window.c </code></pre> <p>and</p> <pre><code> if os(darwin) - include-dirs: - glfw/lib/cocoa - frameworks: - AGL - Cocoa - OpenGL extra-libraries: glfw - extra-lib-dirs: build/static build/dynamic + extra-lib-dirs: build/dynamic </code></pre> <p>I've not tested anything beyond verifying that the following now works properly:</p> <pre><code>➜ GLFW-b git:(master) ✗ ghci GHCi, version 7.0.2: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading package ffi-1.0 ... linking ... done. Prelude&gt; :m + Graphics.UI.GLFW Prelude Graphics.UI.GLFW&gt; initialize Loading package GLFW-b-0.0.2.6 ... linking ... done. True Prelude Graphics.UI.GLFW&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload