man ExtUtils::CBuilder () - Compile and link C code for Perl modules
NAME
ExtUtils::CBuilder - Compile and link C code for Perl modules
SYNOPSIS
use ExtUtils::CBuilder;
my $b = ExtUtils::CBuilder->new(%options); $obj_file = $b->compile(source => 'MyModule.c'); $lib_file = $b->link(objects => $obj_file);
DESCRIPTION
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 CWModule::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!
METHODS
- new
-
Returns a new CWExtUtils::CBuilder object. A CWconfig parameter
lets you override CWConfig.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' } );
- have_compiler
- Returns true if the current system has a working C compiler and linker, false otherwise. To determine this, we actually compile and link a sample C library.
- compile
- Compiles a C source file and produces an object file. The name of the object file is returned. The source file is specified in a CWsource parameter, which is required; the other parameters listed below are optional. Specifies the name of the output file to create. Otherwise the CWobject_file() method will be consulted, passing it the name of the CWsource file. Specifies any additional directories in which to search for header files. May be given as a string indicating a single directory, or as a list reference indicating multiple directories. Specifies any additional arguments to pass to the compiler. Should be given as a list reference containing the arguments individually, or if this is not possible, as a string containing all the arguments together. The operation of this method is also affected by the CWinstallarchlib, CWcccdlflags, CWccflags, CWoptimize, and CWcc entries in CWConfig.pm.
- link
- Invokes the linker to produce a library file from object files. In scalar context, the name of the library file is returned. In list context, the library file and any temporary files created are returned. A required CWobjects 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
- Specifies the name of the output library file to create. Otherwise the CWlib_file() method will be consulted, passing it the name of the first entry in CWobjects.
- module_name
- Specifies the name of the Perl module that will be created by linking. On platforms that need to do prelinking (Win32, OS/2, etc.) this is a required parameter.
- extra_linker_flags
- Any additional flags you wish to pass to the linker. On platforms where CWneed_prelink() returns true, CWprelink() will be called automatically. The operation of this method is also affected by the CWlddlflags, CWshrpenv, and CWld entries in CWConfig.pm.
- link_executable
- Invokes the linker to produce an executable file from object files. In scalar context, the name of the executable file is returned. In list context, the executable file and any temporary files created are returned. A required CWobjects 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 optional parameters are the same as CWlink with exception for
- exe_file
- Specifies the name of the output executable file to create. Otherwise the CWexe_file() method will be consulted, passing it the name of the first entry in CWobjects.
- object_file
-
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. - lib_file
-
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. - exe_file
-
my $exe_file = $b->exe_file($object_file);
Converts the name of an object file to the most natural name of an executable file to create from it. For instance, on Mac OS X the object file foo.o would result in the executable file foo, and on Windows it would result in foo.exe. - prelink
-
On certain platforms like Win32, OS/2, VMS, and AIX, it is necessary
to perform some actions before invoking the linker. The
CWExtUtils::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 CWExtUtils::Mksymlists::Mksymlists()
options, as follows:
Mksymlists() prelink() 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 CWExtUtils::Mksymlists for the details of what these parameters do. - need_prelink
- Returns true on platforms where CWprelink() should be called during linking, and false otherwise.
TO DO
Currently this has only been tested on Unix and doesn't contain any of the Windows-specific code from the CWModule::Build project. I'll do that next.
HISTORY
This module is an outgrowth of the CWModule::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.
AUTHOR
Ken Williams, kwilliams@cpan.org
COPYRIGHT
Copyright (c) 2003-2005 Ken Williams. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
SEE ALSO
perl(1), Module::Build(3)