http://www.perlmonks.org?node_id=1069508

llancet has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing an module with XS. On the last step of linking every thing together, the linker failed:
cc -shared -L/usr/local/lib -fstack-protector -o blib/arch/auto/GenoEy +e/GenoEye.so buildtmp/GenoEye.o -lcairo /usr/bin/ld: cannot find -lcairo collect2: error: ld returned 1 exit status
But the cairo library is out there. I manually run the link command, it runs successful.
$ cc -shared -L/usr/local/lib -fstack-protector -o blib/arch/auto/Geno +Eye/GenoEye.so buildtmp/GenoEye.o -lcairo $ ls blib/arch/auto/GenoEye/ GenoEye.bs GenoEye.so
Why it failed in perl build script? I use Module::Build::WithXSpp and a Build.PL.

Replies are listed 'Best First'.
Re: Failed to link while building XS code
by syphilis (Archbishop) on Jan 06, 2014 at 13:58 UTC
    But the cairo library is out there. I manually run the link command, it runs successful

    Take a close look at the output from the ./Build.PL step - mainly checking to see if there's any mention of a problem locating "-lcairo".

    I'm wondering whether perl, having not been able to find -lcairo, might then do something to the environment that ensures that the linker won't find it either.
    Then, when you run the command manually, it works because you're now running in an environment that perl has not corrupted.

    Just a guess ... I'm not all that familiar with Module::Build ... and firmly committed to staying that way.

    Cheers,
    Rob
      Build.PL does not output anything strange. The cairo library is indexed by ldconfig:
      # ldconfig -p | grep cairo.so libcairo.so.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libcairo +.so.2 libcairo.so.2 (libc6) => /usr/lib/i386-linux-gnu/libcairo.so.2 libcairo.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libcairo.s +o