Skip to content

Instantly share code, notes, and snippets.

@plicease
Last active August 14, 2017 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plicease/4e64a414fb175a9358ee3dc50a0f8ba3 to your computer and use it in GitHub Desktop.
Save plicease/4e64a414fb175a9358ee3dc50a0f8ba3 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Path::Tiny qw( path );
use ExtUtils::CBuilder;
use ExtUtils::ParseXS;
path('Foo.xs')->spew(<<'EOF');
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
MODULE = Foo PACKAGE = Foo
const char *hello()
CODE:
RETVAL = "hello world\n";
OUTPUT:
RETVAL
EOF
ExtUtils::ParseXS->new->process_file(
filename => 'Foo.xs',
output => 'Foo.c',
versioncheck => 0,
prototypes => 0,
);
my $cb = ExtUtils::CBuilder->new;
my $obj = $cb->compile(
source => 'Foo.c',
extra_compile_flags => [],
);
my $lib = $cb->link(
objects => [$obj],
module_name => 'Foo',
extra_linker_flags => [],
);
die 'link returned undef' unless defined $lib;
print "lib = $lib\n";
die 'link returned file not there' unless -f $lib;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment