为什么Dynamic Loader包无法解析功能?

时间:2017-01-26 17:13:51

标签: haskell ghc dynamic-linking

我一直在尝试使用dynamic loader中找到的this question包。我是Haskell的新手,请原谅我,如果我犯了一些令人难以置信的菜鸟错误。我的问题是,当我尝试使用resolveFunctions函数时,我收到以下错误:

DyanmicLoad-exe: /home/ubuntu/DynamicLoadTest/Plugin.o: unknown symbol `ghczmprim_GHCziCString_unpackCStringzh_closure'
DyanmicLoad-exe: user error (Unable to resolve functions!)

如果有人能告诉我可能的错误,我会很高兴。

这是我的代码(我使用的是基本的stack new结构):

应用/ Main.hs 只是主要功能。

module Main where

import Lib

main :: IO ()
main = libMain

的src / Lib.hs 该模块已加载到此处。

module Lib
    ( libMain
    ) where
import System.Plugins.DynamicLoader
import System.Directory
import Interface
libMain :: IO ()
libMain = do currentDir <- System.Directory.getCurrentDirectory
             loadModuleFromPath (currentDir ++ "/Interface.o") Nothing
             putStrLn "Loaded Interface"
             loadedModule <- loadModuleFromPath (currentDir ++ "/Plugin.o") (Just currentDir)
             putStrLn "Loaded Plugin Module!"
             resolveFunctions
             putStrLn "Resolved Functions"
             plugin <- (loadFunction loadedModule "getPlugin") :: IO (JobInterface)
             putStrLn "Loaded Plugin"
             putStrLn (jobName plugin)

的src / Interface.hs 该文件是&#34;插件界面&#34;

module Interface (
   JobInterface (..)
) where

data JobInterface =
     JobInterface { jobName :: String
              , runJob :: Int -> Int
                  }

的src / Plugin.hs 一个示例插件。     模块插件(         getPlugin     )其中

import Interface

getPlugin :: JobInterface
getPlugin = JobInterface "Hello" $ \x -> 1 * x

我正在构建stack build,后跟stack ghc src/Plugin.hs src/Interface.hs。我正在使用stack exec DyanmicLoad-exe

GHC版本是8.0.1

完整输出:

$ stack exec DyanmicLoad-exe
Loaded Interface
Loaded Plugin Module!
DyanmicLoad-exe: /home/ubuntu/DynamicLoadTest/Plugin.o: unknown symbol `ghczmprim_GHCziCString_unpackCStringzh_closure'
DyanmicLoad-exe: user error (Unable to resolve functions!)

编辑1:

构建时使用-dynamic标志出错。

$ stack exec DyanmicLoad-exe
Loaded Interface
Loaded Plugin Module!
DyanmicLoad-exe: /home/ubuntu/DynamicLoadTest/Plugin.o: unhandled ELF relocation(RelA) type 42

DyanmicLoad-exe: user error (Unable to resolve functions!)

编辑2 .cabal文件

name:                DyanmicLoad
version:             0.1.0.0
synopsis:            Initial project template from stack
description:         Please see README.md
homepage:            https://github.com/githubuser/DyanmicLoad#readme
license:             BSD3
license-file:        LICENSE
author:              Author name here
maintainer:          example@example.com
copyright:           2017 Author name here
category:            Web
build-type:          Simple
extra-source-files:  README.md
cabal-version:       >=1.10

library
  hs-source-dirs:      src
  exposed-modules:     Lib
                      , Interface
  build-depends:       base >= 4.7 && < 5
                      , dynamic-loader
                      , directory
  default-language:    Haskell2010

executable DyanmicLoad-exe
  hs-source-dirs:      app
  main-is:             Main.hs
  ghc-options:         -dynamic -threaded -rtsopts -with-rtsopts=-N
  build-depends:       base
                     , DyanmicLoad
  default-language:    Haskell2010

test-suite DyanmicLoad-test
  type:                exitcode-stdio-1.0
  hs-source-dirs:      test
  main-is:             Spec.hs
  build-depends:       base
                     , DyanmicLoad
  ghc-options:         -threaded -rtsopts -with-rtsopts=-N
  default-language:    Haskell2010

source-repository head
  type:     git
  location: https://github.com/githubuser/DyanmicLoad

0 个答案:

没有答案