1
votes

I have written some simplistic code to call a function in a C library. The code compiles (and a similar piece works for a standard C library) but when I compile and link, ghc cannot find the C library. My cabal files is:

executable ttclient
main-is:    MainFFI4TT.hs
build-depends: base
default-language: Haskell2010
hs-source-dirs: src
other-modules:
Include-dirs: treetaggerSourceC 
Includes: tagger-api.h
extra-libraries: libtreetagger
extra-lib-dirs: /usr/lib 

the file libtreetagger.so is in /usr/lib but cannot be found. what else would be reuqired? It does not make a difference whether I use stack build or cabal install (8.0.2 or 8.0.1). cabal is version 1.24.0.0 and the system is linux debian stretch.

I would prefer to keep the library in a user dir and not a system dir. Can this be achieved?

The haskell code is:

foreign import ccall "tagger-api.h init_treetagger"    
    c_initTreeTagger :: CString -> IO ()   
    -- void init_treetagger(char *param_file_name);

mainFFItest :: IO ()
mainFFItest = do 

    c_initTreeTagger "german-utf8.par"
1

1 Answers

7
votes

I assume you're getting the error message:

* Missing C library: libtreetagger

If so, the likely problem is that extra-libraries should list libraries without the lib prefix:

extra-libraries: treetagger