[Haskell-beginners] Error Message: Can not find C library. How can I do this?

S. H. Aegis shaegis at gmail.com
Tue Feb 26 06:47:59 UTC 2019


Hello.

I’m new to stack & FFI.

I created a dll file by http://www.mingw.org/wiki/sampleDLL

And I put all files into dll folder. (Those files are example_dll.cpp,
example_dll.dll, example_dll.h, example_dll.o, example_exe.cpp,
libexample_dll.a) I test example_exe.exe file, and confirmed that works.

(Windows7 Pro, stack 1.9.3)

<package.yaml>

executables:

  test2-exe:

    main:                Main.hs

    source-dirs:         app

    ghc-options:

    - -threaded

    - -rtsopts

    - -with-rtsopts=-N

    dependencies:

    - test2

    extra-libraries:

    - example_dll.a

    extra-lib-dirs:

    - dll

<stack.yaml>

# Extra directories used by stack for building

extra-include-dirs:

  - dll

extra-lib-dirs:

  - dll

<Main.hs>

{-# LANGUAGE ForeignFunctionInterface #-}



module Main where



-- import Lib

import Foreign



foreign import ccall "example_dll.h hello"

    c_hello :: IO()



main :: IO ()

main = c_hello

<example_dll.cpp>

#include <stdio.h>

#include "example_dll.h"



__stdcall void hello(const char *s)

{

        printf("Hello %s\n", s);

}

int Double(int x)

{

        return 2 * x;

}

void CppFunc(void)

{

        puts("CppFunc");

}

void MyClass::func(void)

{

        puts("MyClass.func()");

}



When I try to stack build, I get error messages.



*C:\Users\shaegis\Documents\Haskell\test2\dll>stack build*

*Building all executables for `test2' once. After a successful build of all
of them, only specified executables will be rebuilt.*

*test2-0.1.0.0: configure (lib + exe)*

*Configuring test2-0.1.0.0...*

*Cabal-simple_Z6RU0evB_2.4.0.1_ghc-8.6.3.exe: Missing dependency on a
foreign*

*library:*

** Missing (or bad) C library: example_dll.a*

*This problem can usually be solved by installing the system package that*

*provides this library (you may need the "-dev" version). If the library is*

*already installed but in a non-standard location then you can use the
flags*

*--extra-include-dirs= and --extra-lib-dirs= to specify where it is.If the*

*library file does exist, it may contain errors that are caught by the C*

*compiler at the preprocessing stage. In this case you can re-run configure*

*with the verbosity flag -v3 to see the error messages.*



*--  While building package test2-0.1.0.0 using:*

*
C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_2.4.0.1_ghc-8.6.3.exe
--builddir=.stack-work\dist\e626a42b configure
--with-ghc=C:\Users\shaegis\AppData\Local\Programs\stack\x86_64-windows\ghc-8.6.3\bin\ghc.EXE
--with-ghc-pkg=C:\Users\shaegis\AppData\Local\Programs\stack\x86_64-windows\ghc-8.6.3\bin\ghc-pkg.EXE
--user --package-db=clear --package-db=global
--package-db=C:\sr\snapshots\3233b5e2\pkgdb
--package-db=C:\Users\shaegis\Documents\Haskell\test2\.stack-work\install\784ab3f0\pkgdb
--libdir=C:\Users\shaegis\Documents\Haskell\test2\.stack-work\install\784ab3f0\lib
--bindir=C:\Users\shaegis\Documents\Haskell\test2\.stack-work\install\784ab3f0\bin
--datadir=C:\Users\shaegis\Documents\Haskell\test2\.stack-work\install\784ab3f0\share
--libexecdir=C:\Users\shaegis\Documents\Haskell\test2\.stack-work\install\784ab3f0\libexec
--sysconfdir=C:\Users\shaegis\Documents\Haskell\test2\.stack-work\install\784ab3f0\etc
--docdir=C:\Users\shaegis\Documents\Haskell\test2\.stack-work\install\784ab3f0\doc\test2-0.1.0.0
--htmldir=C:\Users\shaegis\Documents\Haskell\test2\.stack-work\install\784ab3f0\doc\test2-0.1.0.0
--haddockdir=C:\Users\shaegis\Documents\Haskell\test2\.stack-work\install\784ab3f0\doc\test2-0.1.0.0
--dependency=base=base-4.12.0.0
--extra-include-dirs=C:\Users\shaegis\AppData\Local\Programs\stack\x86_64-windows\msys2-20180531\mingw64\include
--extra-include-dirs=C:\Users\shaegis\Documents\Haskell\test2\dll
--extra-lib-dirs=C:\Users\shaegis\AppData\Local\Programs\stack\x86_64-windows\msys2-20180531\mingw64\bin
--extra-lib-dirs=C:\Users\shaegis\AppData\Local\Programs\stack\x86_64-windows\msys2-20180531\mingw64\lib
--extra-lib-dirs=C:\Users\shaegis\Documents\Haskell\test2\dll
--enable-tests --enable-benchmarks*

*Process exited with code: ExitFailure 1*



How can I fix this? I did a lot of things on the webpages, but I could not.

Please, help me.



Sincerely, S. Chang.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20190226/5e4e7d8b/attachment-0001.html>


More information about the Beginners mailing list