ExtUtils::CBuilder - Compile and link C code for Perl modules |
ExtUtils::CBuilder - Compile and link C code for Perl modules
use ExtUtils::CBuilder;
my $b = ExtUtils::CBuilder->new(%options); $obj_file = $b->compile(source => 'MyModule.c'); $lib_file = $b->link(objects => $obj_file);
This module can build the C portions of Perl modules by invoking the
appropriate compilers and linkers in a cross-platform manner. It was
motivated by the Module::Build
project, but may be useful for other
purposes as well. However, it is not intended as a general
cross-platform interface to all your C building needs. That would
have been a much more ambitious goal!
ExtUtils::CBuilder
object. A config
parameter
lets you override Config.pm
settings for all operations performed
by the object, as in the following example:
# Use a different compiler than Config.pm says my $b = ExtUtils::CBuilder->new( config => { ld => 'gcc' } );
source
parameter, which is required; the other parameters listed below are
optional.
object_file
object_file()
method will be consulted, passing it the name of the
source
file.
include_dirs
extra_compiler_flags
The operation of this method is also affected by the
installarchlib
, cccdlflags
, ccflags
, optimize
, and cc
entries in Config.pm
.
objects
parameter contains the name of the
object files to process, either in a string (for one object file) or
list reference (for one or more files). The following parameters are
optional:
lib_file()
method will be consulted, passing it the name of
the first entry in objects
.
On platforms where need_prelink()
returns true, prelink()
will be called automatically.
The operation of this method is also affected by the lddlflags
,
shrpenv
, and ld
entries in Config.pm
.
my $object_file = $b->object_file($source_file);
Converts the name of a C source file to the most natural name of an output object file to create from it. For instance, on Unix the source file foo.c would result in the object file foo.o.
my $lib_file = $b->lib_file($object_file);
Converts the name of an object file to the most natural name of a output library file to create from it. For instance, on Mac OS X the object file foo.o would result in the library file foo.bundle.
ExtUtils::Mksymlists
module does this, writing files used by the
linker during the creation of shared libraries for dynamic extensions.
The names of any files written will be returned as a list.
Several parameters correspond to ExtUtils::Mksymlists::Mksymlists()
options, as follows:
Mksymlists() prelink_objects() type -------------|-------------------|------------------- NAME | dl_name | string (required) DLBASE | dl_base | string FILE | dl_file | string DL_VARS | dl_vars | array reference DL_FUNCS | dl_funcs | hash reference FUNCLIST | dl_func_list | array reference IMPORTS | dl_imports | hash reference
Please see the documentation for ExtUtils::Mksymlists
for the
details of what these parameters do.
prelink()
should be called
during linking, and false otherwise.
Currently this has only been tested on Unix and doesn't contain any of
the Windows-specific code from the Module::Build
project. I'll do
that next.
This module is an outgrowth of the Module::Build
project, to which
there have been many contributors. Notably, Randy W. Sims submitted
lots of code to support 3 compilers on Windows and helped with various
other platform-specific issues.
Ken Williams, kwilliams@cpan.org
perl(1), Module::Build(3)
ExtUtils::CBuilder - Compile and link C code for Perl modules |