This was originally posted to Stack Overflow more than a day ago; if that's a problem I can delete it as it is likely destined to end up as tumbleweed anyway.

I'm trying to export C constants from a system header using ExtUtils::Constant.

As per the doc, I have in Makefile.PL:

ExtUtils::Constant::WriteConstants ( NAME => 'Foo::Bar', NAMES => [ qw(EPOLLIN EPOLLOUT) ] );

Then in Bar.xs:

#include "const-c.inc" #include <sys/epoll.h> // hail mary... MODULE = Foo::Bar PACKAGE = Foo::Bar INCLUDE: const-xs.inc

However, when I run a test with:

is(Foo::Bar::EPOLLOUT, 4);

I get:

t/bar.t Bareword "Foo::Bar::EPOLLOUT" not allowed while "strict subs" in use

This would not be the case if EPOLLOUT existed as a constant; i.e. it's an invalid identifier.

How is this supposed to be done? I am not at all surprised this fails to set EPOLLOUT to the correct value -- the doc also says ExtUtils::Constant "doesn't contain the routines to scan header files to extract these constants" -- but while the .xs code generated is over my head, I am a bit surprised that Foo::Bar::EPOLLOUT is not recognized as an identifier with an undef value, and the fact that it isn't leaves me confused as to what to try next.

I would contemplate the source of another perl module that uses ExtUtils::Constant, but the only one I can think of that exports system defines is POSIX, which is core (if anyone else knows of one please leave a comment).


In reply to Access system constants using ExtUtils::Constants by Anonymous Monk

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.