halfcountplus has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perplexed by Inline::C/MakeMaker LD path
by syphilis (Archbishop) on Mar 02, 2014 at 22:55 UTC | |
by halfcountplus (Hermit) on Mar 03, 2014 at 14:02 UTC | |
by syphilis (Archbishop) on Mar 03, 2014 at 14:33 UTC | |
|
Re: Perplexed by Inline::C/MakeMaker LD path
by Anonymous Monk on Mar 02, 2014 at 20:39 UTC | |
by halfcountplus (Hermit) on Mar 03, 2014 at 14:04 UTC |