åãã¦ã®Devel::BindPP
Standard C++
foo-bar.cpp
#include <iostream> int main () { std::cout << "Hello World"; }
$ gcc -o foo-bar foo-bar.cpp -lstdc++ $ foo-bar Hello Wolrd
Devel::BindPP
$ perl -MDevel::BindPP -e 'use Devel::BindPP::WriteFile()'
foo-bar.cpp
include <iostream> #include "bindpp.h" XS(xs_hello_world) { std::cout << "Hello World"; } extern "C" { XS(boot_Foo__Bar) { pl::BootstrapCtx bc; pl::Package pkg("Foo::Bar", __FILE__); pkg.add_method("hello_world", xs_hello_world); } };
MakeFile.pl
use inc::Module::Install; name 'Foo-Bar'; all_from 'lib/Foo/Bar.pm'; makemaker_args( OBJECT => '$(O_FILES)', LIBS => ['-lstdc++'], ); WriteAll;
lib/Foo/Bar.pm
package Foo::Bar; use strict; use warnings; our $VERSION = '0.00001'; use XSLoader; XSLoader::load __PACKAGE__, $VERSION; 1;
$ perl MakeFile.pl $ make $ perl -Mblib -MFoo::Bar -e 'Foo::Bar::hello_world' HelloWorld