EXTUTILS::CBUILDER(3pm)
π ExtUtils::CBuilder π
okay so bestie, welcome to ExtUtils::CBuilder β straight out of the Perl Programmers Reference Guide, no cap. this is the little module that handles the C parts of your Perl modules so you don't have to scream at make at 2am π«Ά
β¨ 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);
that's the whole vibe honestly. make a builder, compile a thing, link a thing. iconic πΈ
π DESCRIPTION π
so this module builds the C portions of Perl modules by invoking the appropriate compilers and linkers in a cross-platform way β¨ it was motivated by the Module::Build project, but it may be useful for other purposes as well.
but hear me when I say this β 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! π so like, don't come for it with your whole entire toolchain, it's doing one job and it's slaying at that one job π
π METHODS π
β new
Returns a new 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' } );
A quiet parameter tells CBuilder to not print its system() commands before executing them:
# Be quieter than normal
my $b = ExtUtils::CBuilder->new( quiet => 1 );
so like, if the command spam is giving too much main character energy for your terminal, quiet is your girl π
β have_compiler
Returns true if the current system has a working C compiler and linker, false otherwise π―
and the way it finds out? it literally just tries it β we actually compile and link a sample C library. no vibes-based guessing here, it's a real vibe check π
the sample will be compiled in the system tempdir or, if that fails for some reason, in the current directory π
β have_cplusplus
Just like have_compiler β but for C++ instead of C π₯ same energy, different language.
β 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 source parameter, which is required; the other parameters listed below are optional π
object_fileβ Specifies the name of the output file to create. Otherwise theobject_file()method will be consulted, passing it the name of thesourcefile.include_dirsβ 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. πextra_compiler_flagsβ 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.C++β Specifies that the source file is a C++ source file and sets appropriate compiler flags π₯
also heads up bestie: the operation of this method is also affected by thearchlibexp,cccdlflags,ccflags,optimize, andccentries inConfig.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 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β Specifies the name of the output library file to create. Otherwise thelib_file()method will be consulted, passing it the name of the first entry inobjects.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 need_prelink() returns true, prelink() will be called automatically βοΈ
and again, this method is also affected by thelddlflags,shrpenv, andldentries inConfig.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 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 optional parameters are the same as link β with the exception of:
exe_fileβ Specifies the name of the output executable file to create. Otherwise theexe_file()method will be consulted, passing it the name of the first entry inobjects.
β 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 β it's giving "we know what you meant" β¨
β 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 π (Windows really said "gotta have the extension, bestie")
β prelink
okay so on certain platforms like Win32, OS/2, VMS, and AIX, it is necessary to perform some actions before invoking the linker π€
the 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() 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
VERSION | dl_version | string
Please see the documentation for ExtUtils::Mksymlists for the details of what these parameters do π (iykyk, go read it, it's right there)
β need_prelink
Returns true on platforms where prelink() should be called during linking, and false otherwise β
β
β extra_link_args_after_prelink
Returns a list of extra arguments to give to the link command π«Ά
the arguments are the same as for prelink(), with the addition of an array reference to the results of prelink(); this reference is indexed by key prelink_res π―
π§ TO DO π§
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 π (we believe in you, whoever "I" is)
π HISTORY π
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. Ilya Zakharevich has contributed fixes for OS/2; John E. Malmberg and Peter Prymmer have done likewise for VMS πππ
π«Ά SUPPORT π«Ά
ExtUtils::CBuilder is maintained as part of the Perl 5 core π
Please submit any bug reports via the perlbug tool included with Perl 5. Bug reports will be included in the Perl 5 ticket system at <https://rt.perl.org> π
The Perl 5 source code is available at <https://perl5.git.perl.org/perl.git> and ExtUtils-CBuilder may be found in the dist/ExtUtils-CBuilder directory of the repository πβ¨
π AUTHOR π
Ken Williams, kwilliams@cpan.org
Additional contributions by The Perl 5 Porters π
π 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 πΈ
and that's the whole page bestie, you ate π
β¨ sign-off time: this was perl v5.42.3, dated 2026-11-03, living its best life as ExtUtils::CBuilder(3pm) β go compile something iconic π¦π
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms