How do I statically compile a C library into a Haskell module that I can later load with the GHC API? -
How do I statically compile a C library into a Haskell module that I can later load with the GHC API? -
here desired utilize case:
i have bundle single module reads hdf5 files , writes of info haskell records. work, library uses bindings-hdf5 package. here cabal's build-depends. reader-types module wrote defines types of haskell records contain read-in data.
build-depends: base of operations >=4.7 && <4.8 , text , vector , containers , bindings-hdf5 , reader-types note cabal file not utilize extra-libraries or ghc-options. can load module, src/mabel.hs in ghci long specify required hdf5_hl library:
ghci src/mabel.hs -lhdf5_hl -l/long/nixos/path/lib and within ghci, can run function fine.
now, want compile library/module single, compiled file can later load ghc api in different haskell program. single file, mean needs run if hdf5_hl library not exist on system. preferably, run if text, vector, and/or containers missing, not essential because reader-types requires types anyway. when loading module ghc api, want load in compiled form, , not run interpreted.
my purpose doing want self-contained file deed single, pre-compiled plugin file later loaded , executed different haskell executable. other plugins might not utilize hdf5 @ all, , bundle guaranteed utilize reader-types, defines plugin interface types.
the hdf5 library on scheme contains next files: libhdf5_la.la, libhdf5_hl.so, libhdf5.la, libhdf5.so, , similar files have version number in file name.
i have done lot of googling, getting confused border cases finding. here examples i'm either sure don't fit case, or can't tell.
i not want compile haskell library utilize c or python, haskell programme using ghc api. i not want compile c wrappers c++ library haskell module because bindings exist , library c library. i not want compile library exclusively self-contained because, since loading ghc api, don't need ghc runtime included in library. (my understanding plugins must compiled same ghc version loaded in ghc api). i not want compile c bindings , c library @ same time because c library compiled , bindings specified in separate bundle (bindings-hdf5). the closest resource want this exchange on mailing list 2009. however, added extra-libraries: hdf5_hl or extra-libraries: hdf5 cabal file, , in both cases resulting .a, .so, .dyn_hi, .dyn_o, .hi, , .o files in dist/build exact same size without using extra-libraries, i'm confident not working correctly. what changes cabal file need create create self-contained, standalone file can later load ghc api? if not possible, alternatives?
instead of using ghc api, open using plugins library load plugin, self-contained requirements still same.
edit: not care form compiled "plugin" must take (i assume object file right way), want load dynamically separate executable @ run time , execute functions defines known names , known types. reason want single file there other different plugins, , want them behave same way without having worry lib paths , dependencies each one. compiled, single file simpler interface doing zipping/unzipping archives include haskell object code , dependencies.
haskell ghc cabal
Comments
Post a Comment