The compiler option -L/usr/local/lib does not automatically add the path to the list of runtime library search paths. It only makes the library be found at compile time.  Unless /usr/local/lib is otherwise configured to be searched by the dynamic linker, the shared library won't be found at runtime (which seems to be the problem in your case).

The runtime library search paths are normally set using the linker option -rpath, or the environment variable LD_RUN_PATH (at compile time).

That's where MakeMaker comes in (or should). Normally, it would take care of setting the appropriate LD_RUN_PATH when it sees something like LIBS => ['-L/usr/local/lib -lgeotiff'].  In the generated Makefile you should find definitions like

# See ExtUtils::Liblist for details # EXTRALIBS = -L/usr/local/lib -lgeotiff LDLOADLIBS = -L/usr/local/lib -lgeotiff BSLOADLIBS = LD_RUN_PATH = /usr/local/lib

which would then prepend LD_RUN_PATH="/usr/local/lib" to the gcc -shared ... -L/usr/local/lib -lgeotiff command line.  I'm not sure why this isn't happening in your case.

In addition to adding /usr/local/lib to LD_LIBRARY_PATH (which is ugly, as it always needs extra fiddling at runtime), you could try the following workarounds:

(1) specify the appropriate -rpath yourself. For this, you'd need to somehow get -Wl,-rpath=/usr/local/lib into the link command. This isn't quite as easy as you might think, because Inline::C's LDDLFLAGS option doesn't allow adding to it, so you'd need to re-specify all other options, which you typically wouldn't know, as they are being auto-configured...  What does seem to work, though, is misusing the LD option, by setting

LD => 'gcc -Wl,-rpath=/usr/local/lib'

(which did create the appropriate linker command line, for me)

(2) In case you also have a static library libgeotiff.a, you could link against that one, in which case you wouldn't have any additional runtime dependencies (the static lib would need to have been compiled with -fPIC, though, because it will be linked with a shared lib).  If you have both shared (.so) and static (.a) versions in /usr/local/lib, you'd need to move away the shared one, because gcc defaults to using the shared lib, if found. Alternatively, specify the full path to the .a file directly via MYEXTLIB (instead of -L/usr/local/lib -lgeotiff), i.e.

MYEXTLIB => '/usr/local/lib/libgeotiff.a'

In reply to Re: Inline::C external library linking problem by almut
in thread Inline::C external library linking problem by whakka

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.