[Haskell-cafe] Adding a custom lib to stack project

Yotam Ohad yotam2206 at gmail.com
Tue Sep 11 17:48:39 UTC 2018


Hi Tamar,

I managed to build at the end by adding the c source files with
`c-sources:` in package.yaml
Thanks for your help

Yotam

‫בתאריך יום ג׳, 11 בספט׳ 2018 ב-20:43 מאת <‪lonetiger at gmail.com‬‏>:‬

>
>
> Hi Yotam,
>
>
>
> Have you tried with cabal? If that gives the same error can you paste your
> cabal file somewhere and I can take a look for you.
>
>
>
> Cheers,
>
> Tamar
>
>
>
> *From: *Phyx <lonetiger at gmail.com>
> *Sent: *Tuesday, September 11, 2018 08:50
> *To: *Yotam Ohad <yotam2206 at gmail.com>
> *Cc: *haskell-cafe at haskell.org
> *Subject: *Re: [Haskell-cafe] Adding a custom lib to stack project
>
>
>
> I don't use stack so can't help you much there. If you can get it to put
> ghc in verbose mode you can see what it's passing to the compiler. If the
> error is coming from stack itself then you'll need to figure out how stack
> tests for the library.
>
> On Tue, Sep 11, 2018, 08:32 Yotam Ohad <yotam2206 at gmail.com> wrote:
>
> Thanks for the reply.
>
> I've added extra-libraries to package.yaml.
>
> Now though, I'm getting a missing C library error (although `stack path
> --extra-library-dirs` prints the directory of the .lib file)
>
>
>
> Yotam
>
>
>
> ‫בתאריך יום ג׳, 11 בספט׳ 2018 ב-10:03 מאת ‪Phyx‏ <‪lonetiger at gmail.com‏>:
>
> Hi,
>
>
>
> I assume CreateDebuggedProcess is defined in bindings.lib? You need to
> also add extra-libraries: bindings
>
>
>
> Also keep in mind that C++ has a different name mangling than C, so if
> your function is in a class you'll need to use the proper name for it.
>
>
>
> nm -g bindings.lib would show the actual name.
>
>
>
> Tamar.
>
>
>
> On Tue, Sep 11, 2018, 07:51 Yotam Ohad <yotam2206 at gmail.com> wrote:
>
> Hi,
>
> I made a lib from a  cpp project with one function: BOOL Foo(LPCSTR bar)
> In the stack project I added the .lib file's folder to the
> extra-lib-dirs/extra-include-dirs and then, in main:
>
> {-# LANGUAGE ForeignFunctionInterface #-}
>
> module Main where
>
> import System.Win32.Types
> import Foreign.C.String
>
> main :: IO ()
> main = do
>     withCString "bar" c_Foo
>     putStrLn "success"
>
> foreign import ccall "bindings.lib Foo"
>     c_Foo :: LPCSTR -> IO BOOL
>
> When building I get the following error
> Building all executables for `tape' once. After a successful build of all
> of them, only specified executables will be rebuilt.
> tape-0.1.0.0: build (lib + exe)
> Preprocessing library for tape-0.1.0.0..
> Building library for tape-0.1.0.0..
> ignoring (possibly broken) abi-depends field for packages
> Preprocessing executable 'tape-exe' for tape-0.1.0.0..
> Building executable 'tape-exe' for tape-0.1.0.0..
> Linking .stack-work\dist\7d103d30\build\tape-exe\tape-exe.exe ...
> .stack-work\dist\7d103d30\build\tape-exe\tape-exe-tmp\Main.o:fake:(.text+0x102):
> undefined reference to `CreateDebuggedProcess'
> collect2.exe: error: ld returned 1 exit status
> `gcc.exe' failed in phase `Linker'. (Exit code: 1)
>
> --  While building custom Setup.hs for package tape-0.1.0.0 using:
>
> C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_2.2.0.1_ghc-8.4.3.exe
> --builddir=.stack-work\dist\7d103d30 build lib:tape exe:tape-exe
> --ghc-options " -ddump-hi -ddump-to-file -fdiagnostics-color=always"
>     Process exited with code: ExitFailure
>
>
>
> What am I doing wrong?
>
> Yotam
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180911/e4656584/attachment.html>


More information about the Haskell-Cafe mailing list