Skip to content

library with executable can fail when library uses FFI #36

@claudeha

Description

@claudeha

Cabal file (works with cabal):

cabal-version:      1.24
name:               hello
version:            0
synopsis:           test for FFI
license:            PublicDomain
license-file:       LICENSE
author:             Claude Heiland-Allen
maintainer:         claude@mathr.co.uk
category:           Testing
build-type:         Simple

library
    default-language: Haskell2010
    other-extensions:
      ForeignFunctionInterface
    hs-source-dirs:   hs
    exposed-modules:  Hello
    include-dirs:     c
    install-includes: hello.h
    c-sources:        c/hello.c
    build-depends:    base < 5

executable hello
    default-language: Haskell2010
    hs-source-dirs:   hs
    main-is:          Main.hs
    build-depends:    base < 5,
                      hello

result with mcabal:

mhs-hello/hello$ mcabal install
mcabal: Building library hello
mcabal: Building executable hello
mcabal: Build dist-mcabal/bin/mhs/hello with mhs
/tmp/mhsctjva72.c:9:10: fatal error: hello.h: No such file or directory
    9 | #include "hello.h"
      |          ^~~~~~~~~
compilation terminated.

mhs: uncaught exception: error: command failed: cc -w -Wall -O3 -DWANT_GMP=1 -I/home/claude/.mcabal/mhs-0.15.5.0/packages/MicroHs-0.15.5.0/data/src/runtime -I/home/claude/.mcabal/mhs-0.15.5.0/packages/MicroHs-0.15.5.0/data/src/runtime/unix  -D__MHS__ '-DVERSION_ghc_compat="0.5.6.0"' '-DMIN_VERSION_ghc_compat(x,y,z)=((x)<0||(x)==0&&(y)<5||(x)==0&&(y)==5&&(z)<=6)' '-DVERSION_base="4.19.1.0"' '-DMIN_VERSION_base(x,y,z)=((x)<4||(x)==4&&(y)<19||(x)==4&&(y)==19&&(z)<=1)'  /home/claude/.mcabal/mhs-0.15.5.0/packages/MicroHs-0.15.5.0/data/src/runtime/main.c /home/claude/.mcabal/mhs-0.15.5.0/packages/MicroHs-0.15.5.0/data/src/runtime/eval.c /tmp/mhsctjva72.c -lgmp -lm -odist-mcabal/bin/mhs/hello

mcabal: uncaught exception: error: "./lib/System/Process.hs",22:22: callCommand: failed 256, cmd=
"mhs -i -ihs -idist-mcabal/autogen -pdist-mcabal/hello-0.pkg '-DVERSION_ghc_compat=\"0.5.6.0\"' '-DMIN_VERSION_ghc_compat(x,y,z)=((x)<0||(x)==0&&(y)<5||(x)==0&&(y)==5&&(z)<=6)' '-DVERSION_base=\"4.19.1.0\"' '-DMIN_VERSION_base(x,y,z)=((x)<4||(x)==4&&(y)<19||(x)==4&&(y)==19&&(z)<=1)' -z -a. -odist-mcabal/bin/mhs/hello hs/Main.hs"

workaround: add to executable

    -- mcabal bug
    -- these lines should not be necessary
    -- but are to workaround failure with FFI
    -- that cannot find hello.h when compiling
    include-dirs:     c
    c-sources:        c/hello.c

full test project (subdirectory hello):

git clone https://code.mathr.co.uk/mhs-hello.git

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions