Use relative paths for extra-lib-dirs on cabal

I have a C library "myboo" that has a Makefile. I want to make a wrapper for this library. I do not want to install it in / usr / local, since "myboo" is not the main module. In addition, it is recommended that you create "myboo" not as a dynamic library but as a static library.

I create custom Setup.py to create "myboo";

main :: IO () main = defaultMainWithHooks simpleUserHooks { preBuild = \ab -> makeLib ab >> preBuild simpleUserHooks ab } makeLib :: Args -> BuildFlags -> IO () makeLib _ flags = do let verbosity = fromFlag $ buildVerbosity flags cflags <- lookupEnv "CFLAGS" >>= return . maybe "" id setEnv "CFLAGS" $ "-fPIC" ++ (' ' : cflags) rawSystemExit verbosity "env" ["make", "--directory=myboo", "libmyboo.a"] 

And I am settling myboo.cabal to link my haskell codes to the C library;

 library exposed-modules: MyBoo build-depends: base >=4.7 && <4.8 hs-source-dirs: src default-language: Haskell2010 include-dirs: myboo extra-libraries: myboo extra-lib-dirs: myboo 

When I run "cabal build", I received the following messages.

 myboo-0.1.0.0: library-dirs: myboo is a relative path which makes no sense (as there is nothing for it to be relative to). You can make paths relative to the package database itself by using ${pkgroot}. (use --force to override) 

If I write "extra-lib-dirs: / absolute / path / to / working / dir / myboo", it seems to work fine. But this is not very good, because / absolute / ... is only a working directory.

How can I fix the above error messages? My environment is here;

 % ghc --version The Glorious Glasgow Haskell Compilation System, version 7.8.2 % cabal --version cabal-install version 1.20.0.2 using version 1.20.0.0 of the Cabal library % cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=14.04 DISTRIB_CODENAME=trusty DISTRIB_DESCRIPTION="Ubuntu 14.04 LTS" 
+6
source share
2 answers

You can write your own Setup.hs and configure Distribution.Simple.confHook . In your hook function, change Distribution.PackageDescription.extraLibDirs to include the directory.

Note that you also need to change the build-type to Custom in your cabal file.

Here is a link to Setup.hs in which I did what I wrote.

+7
source

A little late, but ...

Now you can use the relative path to set the extra-include-dirs and extra-lib-dirs stack.yaml in stack.yaml . For example, for some package A it will look like this:

 extra-include-dirs: - ../my-c-lib/src extra-lib-dirs: - ../my-c-lib/build 

assuming both A and my-c-lib are stored in the same folder.

What is it. This does not require setting the LD_LIBRARY_PATH variable (until you run the executable). But if you have package B that uses A , you need to add A extra-..-dirs to B stack.yaml . Otherwise, you will receive a Missing C library error. In addition, you need to set LD_LIBRARY_PATH here to prevent can't load .so/.DLL error while creating B

This is basically a temporary solution for creating local packages. I would not use it for a public package, because it forces the user to either modify stack.yaml or store dependent packages in the same folder.

0
source

Source: https://habr.com/ru/post/971402/


All Articles