http://qs321.pair.com?node_id=1169359


in reply to Re^3: With Inline::C, how to link to external library? (;)
in thread With Inline::C, how to link to external library?

You sent me down the right path from what I can tell, tye.

On a different computer, different version of Perl (5.18 vs 5.24 which I was using yesterday), I was having the exact same issue, but I eventually tracked down something that fixed the issue, albeit I'm sure it's wrong.

In /usr/lib/perl/5.18/CORE/XSUB.h which the error was referencing (same file, different location on yesterday's test), I made this change (ie. I removed void):

diff XSUB.h.orig XSUB.h 141c141 < # define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__un +used__) --- > # define XS_EXTERNAL(name) name(pTHX_ CV* cv __attribute__unused_ +_)

I also slightly changed up my Inline::C test code to this (which also breaks without the above change):

use warnings; use strict; use Inline (C => 'DATA', libs => ' -lwiringPi'); say(); __DATA__ __C__ #include <stdio.h> #include <wiringPi.h> void say(){ pinMode(1, INPUT); printf("hello, world!\n"); }

It works!

If I remove the libs directive in the use Inline::C ... statement, I get undefined symbol PinMode, which I fully expect. Put it back in, and voila... things work.

Without removing the void identifier, it breaks when trying to use ANY external shared library, whether it can be found or not. This is easily reproduceable... just try to include a library that does or doesn't exist on the system. As soon as it tries to do EXTERN type stuff, the line that I removed void from is triggered, and breaks.

Does my change look proper to you? Is this a bug? I'm not sure how to test this without using Inline::C to see if it's a global XS thing, or just Inline thing. After I get some more feedback, I'll be glad to test further.

Replies are listed 'Best First'.
Re^5: With Inline::C, how to link to external library? (code)
by tye (Sage) on Aug 08, 2016 at 17:07 UTC

    So, I'm glad that you found a work-around. But it would be good to figure out a more correct fix. Please post the (generated) code before the use of XS_EXTERNAL() to help diagnose what is being included before that use that makes the inclusion of the return type a syntax error.

    - tye        

      Well, after it was sorted that I was using END instead of DATA which was the REAL problem, I continued on. It's a lot easier to create an XS module than I first thought :)

      Anyway, here's the XS code for my first real working Perl prototype.

      The full module is here: RPi::DHT11::EnvControl.