3
votes

I am trying to write ffi for pdflib library ( pdflib.com ) using c2hs on 64 linux. You can download pdflib from their website for free (fully functional eval.)

I tried to compile and run their hello.c demo program and it works fine.

As far as i understand i need only 2 files to make it work: pdflib.h and libpdf.a

So i put both of them into hello folder, wrote a chs file, it compiles and generates hs file fine. But when i try to compile my Hello.hs program cabal complains

Cabal: Missing dependency on a foreign library: * Missing C library: pdflib

I tried giving it the folder name via --extra-include-dirs and --extra-lib-dirs but it does not help.

How do i compile haskell program with pdflib.h and libpdf.a files ?

2
first: I assume you've got "extra-libraries: pdf" like in your cabal file? You need to make sure the name matches precisely (i.e. is the same as the library file but without the 'lib' prefix). second, i've had mixed results with .a files, probably through my own ignorance, but always had success with .so files.sclv
Thanks! That did help. I did not know that i need to remove the "lib" prefix. Now i get bunch of other errors, but that's a different story (gcc, makefiles, g++)Vagif Verdi

2 Answers

2
votes

Migrated from a comment to an answer:

first: I assume you've got "extra-libraries: pdf" like in your cabal file? You need to make sure the name matches precisely (i.e. is the same as the library file but without the 'lib' prefix). second, i've had mixed results with .a files, probably through my own ignorance, but always had success with .so files. – sclv 19 hours ago

0
votes

The linker will need to be able to find your .a file. It will look in the usual /usr/lib paths. Can you install pdflib into the regular system locations (e.g. via your package manager)? This will be the easiest path.