The following short C program can be compiled gcc test.c -lmpg123 and run without error:

#include <stdio.h> #include <mpg123.h> int main (void) { int check = mpg123_init(); if (check != MPG123_OK) fprintf(stderr,"fail: %s\n", mpg123_plain_strerror(check)); return 0; }

And yet, on the exact same system, the following perl program fails with undefined symbol: mpg123_init, indicating libmpg123 has not been linked:

#!/usr/bin/perl use strict; use warnings FATAL => qw(all); use Inline 'C' => Config => CLEAN_AFTER_BUILD => 0, LIBS => '-lmpg123'; use Inline 'C'; Inline->init(); test(); __DATA__ __C__ #include <mpg123.h> void test () { fprintf(stderr,"%d\n", mpg123_init()); }

If I add -L/usr/local/lib to LIBS, then everything works out.

However, ld --verbose output includes SEARCH_DIR("/usr/local/lib") -- notice, I did not need an to use -L when compiling the C version -- and for what it's worth, ldconfig also includes /usr/local/lib in the runtime path. This means Inline::C or MakeMaker is doing its own thing when looking for the libraries; if I look at the Makefile in the _Inline/build directory, the "MakeMaker const_loadlibs section", which should contain the stuff from LIBS, is empty (unless I use -L). A comment there refers to the ExtUtils::Liblist pod, where EXTRALIBS (from this same section of the Makefile) is described:

List of libraries that need to be linked with when linking a perl binary which includes this extension. Only those libraries that actually exist are included.

But no explanation for how the (non-)existence of a library is determined.

Obviously, I cannot deploy this (without requiring the source be edited on each system) if I cannot be certain that Inline::C will find libraries which are otherwise accessible by the normal rules. Any form of insight is appreciated.


In reply to Perplexed by Inline::C/MakeMaker LD path by halfcountplus

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.