Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by tye (Sage)
on Aug 07, 2016 at 23:16 UTC ( #1169315=note: print w/replies, xml ) Need Help??


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

See the "Dynamic Linking" section of "perl -V". My first thought was that you may need to specify changes/additions to one or more of ccdlflags, cccdlflags, and lddlflags, perhaps dropping parts of what you specified to be added to CCFLAGS.

But, after several tries, I finally did find the actual error amid all of the context information:

error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ # define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unu +sed__) ^

Which sounded like a C preprocessor directive was being interpreted as C code. But then I realized that this was just more (actually helpful) context information and the location of the error was actually shown as:

perl_pl_b1a3.c:163:1: note: in expansion of macro ‘XS_EXTERNAL’ XS_EXTERNAL(boot_perl_pl_b1a3); /* prototype to pass -Wmissing-protot +ypes */ ^

Which tells me that you need to look at the line(s) before that, line 162 of perl_pl_bla3.c, where you are likely missing some terminating punctuation, like a ';'. Or you have some unclosed construct (like a comment or quoted string or such). The error could be further up from line 162, of course, and perhaps even in some other file (if line 163 is almost immediately preceeded by an #include, for example).

I didn't notice any mistakes that would explain this problem in the C code that you posted.

But I was surprised at a very specific path to your typemap definitions:

'TYPEMAPS' => [ '/home/pi/perl5/perlbrew/perls/perl-5.24.0/lib/5.24.0/ExtUtils/typ +emap' ],

- tye        

Replies are listed 'Best First'.
Re^4: With Inline::C, how to link to external library? (;)
by stevieb (Canon) on Aug 08, 2016 at 14:38 UTC

    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.

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1169315]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2020-10-28 03:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (259 votes). Check out past polls.

    Notices?