Vagif Verdi
Vagif Verdi

Reputation: 4906

how to use the shared library from haskell without a header file?

I have pdflib_py.so library i want to call from haskell. I do not have a header file. And as you can see the lib's name is not in the standard libbla form.

How do i access it from haskell ?

I followed c2hs tutorial. But it requires a header file (which i do not have) and ghc requires a library name to be in libbla format. I could of course rename pdflib_py.so to libpdfpy.so, in fact i tried it (it did not work), but that's silly to assume that you cannot access a library from haskell because of its name. I'm surely missing something here.

You can download the pdflib library from here http://www.pdflib.com/download/pdflib-family/pdflib-8/

They have bundles for c++, java, php, python etc.

Why don't i use c++ library but a python one ? Well, c++ library libbpdf.a requires to be compiled with g++. And haskell does not work with g++, I would have to write a C wrapper first. Luckily someone already did it for me. That's what a pdflib_py.so is - a c wrapper over libpdf library.

So, how do i use a library with non standard name and no header file from haskell ?

Upvotes: 2

Views: 492

Answers (1)

Tener
Tener

Reputation: 5279

I dont think your approach is correct. You should compile pdflib with g++ into a shared library and then link against it. The C++ library they provide already uses "extern C" wrapper so the symbols exported will be excatly as you would expect them to be.

To sum up, I propose the following solution:

  1. Download C++ bundle
  2. Compile with g++ to make shared .so library
  3. Use header .h file from bundle to make Haskell bindings
  4. Link Haskell code against .so library

Upvotes: 4

Related Questions