Skip to content

Can't build native-static foreign library on Linux x86_64

Summary

Setting the cabal foreign-library type attribute to native-static produces the following error:

Error: [Cabal-4574]
Cannot build some foreign libraries: We can currently only build shared foreign libraries on Linux

Steps to reproduce

To reproduce the issue, in an empty folder add:

  • foreign-static.cabal:
cabal-version:      3.4
name:               foreign-static
version:            0.1

foreign-library foreign-static
    type:             native-static
    other-modules:    ForeignStatic
    build-depends:    base
    default-language: GHC2021
  • ForeignStatic.hs:
module ForeignStatic where

foreign export ccall greet :: IO ()

greet :: IO ()
greet = putStrLn "Hello Static Haskell"

Then run cabal build

Expected behavior

I expect to get a shared library that doesn't depend on any libHS* dependency, as described in https://www.hobson.space/posts/haskell-foreign-library/

Environment

  • GHC version used: ghc 9.12.2, cabal 3.14.2.0

Optional:

  • Operating System: Fedora Linux 42
  • System Architecture: x86_64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information