----- Original Message -----
From: "Michael Roberts" <mich...@vivtek.com>
To: <inline@perl.org>
Sent: Sunday, March 11, 2012 3:45 PM
Subject: Question about writing a CPAN module based on Inline::C
I'm toying with the idea of writing a new Image::Magick wrapper that,
you know, actually compiles on systems like mine. Here's my question,
and this is really more a module configuration question than strictly an
Inline question, but: given that the LIB and INCLUDE directories could
be essentially anywhere and have to be found at install time, how do I
tell Inline *at install time* what values to use for LIB and INCLUDE?
I know how to find these directories at install time - the existing
PerlMagick does that already - although it does it wrong for the latest
version of ImageMagick, ugh - and I know how to tell Inline where
directories are for its compilation step, but I don't actually see how
to combine these two, so that the invocation of Inline::C in the module
would reflect the paths found at install time.
Any ideas would be welcome, even just pointers to something on CPAN that
does this already. Thanks!
I keep thinking I should be able to understand the question ... but I can't
quite :-)
Is the "install time" at which you want to tell Inline the LIBS and INC
values the same as the "install time" at which you know "how to find these
directories" ?
It might be that Devel::CheckLib has something to offer you.
It will enable you to *portably* run (at the 'Makefile.PL' or 'Build.PL'
stage of the build/installation of your module) C programs aimed at testing
that all of the prerequisite headers and libraries have been identified and
located.
If any of those C programs (which *you* have to provide) fail to compile,
then you can tell the user to provide correct paths and try again.
I've not actually used Devel::CheckLib, but let's say I want to find out
whether gmp.h gets found by default. I could then provide in my source
distro a C program that contains simply:
#include <gmp.h>
int main (void) {return 0;}
Then have Devel::CheckLib run that program. If it compiles then I know that
gmp.h is being found by default. If it doesn't, the user gets a message to
provide the path to gmp.h.
Having established that gmp.h is locatable, I can then determine whether
libgmp is found by re-running that same program (again using
Devel::CheckLib) but, this time, supplying an '-lgmp' to the compilation
command.
Success would mean that the library was locatable, but failure would result
in another message to the user asking for the location of the gmp import
library.
Where it gets tricky is when one system might call the library 'gmp' but
another might call it 'gnump' ... or if there might be additional libraries
that need to be linked in on some systems ... or if the number and/or names
of libraries depends upon the method used to build the library(s).
As far as Inline goes, you just provide header and library paths via:
use Inline C => Config =>
LIBS => '-L/full/path/to/additional/libs -llib1 -llib2 -letc',
INC => '/full/path/to/additional/headers;
but I'm thinking you already knew that.
Of course, if libraries in /full/path/to/additional/libs are going to be
found automatically then you can simply specify LIBS as:
LIBS => '-llib1 -llib2 -letc',
Cheers,
Rob