sandbox.cabal
pkgconfig-depends: libavcodec
Main.hs
foreign import capi "libavcodec/avcodec.h avcodec_version"
c_avcodecVersion :: CInt
Just wanted to know how I would be able to add C libraries especially using the pkgconfig-depends
in cabal. Currently lost on where to add pkgs.ffmpeg.lib
and pkgs.ffmpeg.dev
.
Srid has marked this topic as unresolved.
Hmm, I think we should create a documentation page for this.
Quick answer: you need staticWhich
along with extraBuildDepends
. You already use the later, just need the former.
Thanks, @Srid ! I'm a huge fan, btw.
This worked:
cowsayBin :: FilePath
cowsayBin = $(staticWhich "cowsay")
cowsay :: IO String
cowsay = do
(_, mhout, _, _) <- createProcess (shell $ show cowsayBin <> " hola") { std_out = CreatePipe }
case mhout of
Just hout -> hGetContents hout
Nothing -> pure "mhout failed"
Would staticWhichNix be a better fit?
Is there a reason this way is better?
On my previous iteration of this flake (not using haskell-flake
) I used pkgs.haskell.lib.addBuildDepends
this way and that worked. Are there advantages to using the which
package?
Thanks again and cheers all the way from Querétaro, México : )
Great. Yes, using staticWhich
basically hardcodes the full path to the binary at compile time, so it is guaranteed to be available on user's systems. Otherwise, you rely on it being in $PATH.
staticWhichNix
is the same, but expects it to to be in Nix store, thus limiting your software to work only on Nix
Its implementation is simple enough to see what's going on: https://hackage.haskell.org/package/which-0.2.0.2/docs/src/System.Which.html#staticWhichNix
I retract what I said about it working with pkgs.haskell.lib.addBuildDepends
. I thought it did because I had no errors, but that was because I wasn't using it at all. I also had to use the which
package to make it work on my previous flake iteration.
Last updated: Feb 05 2025 at 17:45 UTC