# perldoc > ExtUtils::CBuilder

---
type: CommandReference
command: ExtUtils::CBuilder
mode: perldoc
section: 
source: perldoc
---

## Quick Reference
- `my $b = ExtUtils::CBuilder->new(quiet => 1)` — create a new builder object
- `$b->have_compiler` — check for a working C compiler/linker
- `$obj = $b->compile(source => 'MyModule.c')` — compile a C source file
- `$lib = $b->link(objects => [$obj1, $obj2])` — link object files into a library
- `$exe = $b->link_executable(objects => $obj)` — link an executable
- `$b->object_file('foo.c')` — derive object filename from source name
- `$b->lib_file('foo.o')` — derive library filename from object file

## Name
Compile and link C code for Perl modules

## Synopsis
perl
use ExtUtils::CBuilder;

my $b = ExtUtils::CBuilder->new(%options);
$obj_file = $b->compile(source => 'MyModule.c');
$lib_file = $b->link(objects => $obj_file);
## Methods

### Construction
- `new(%options)` — Create a new builder object. Recognized parameters:
  - `config` — Hash reference overriding `Config.pm` settings (e.g., `{ ld => 'gcc' }`)
  - `quiet` — Suppress printing of `system()` commands (`1` for quiet)

### Capability checks
- `have_compiler` — Returns true if a working C compiler/linker exists (compiles and links a sample library in tempdir).
- `have_cplusplus` — Same as `have_compiler` but for C++.

### Compilation and linking
- `compile(%params)` — Compile a C/C++ source file and return the object file name. Required: `source`. Optional:
  - `object_file` — Output filename; defaults to `object_file($source)`
  - `include_dirs` — String or array ref of extra include directories
  - `extra_compiler_flags` — Array ref or string of additional compiler flags
  - `C++` — Treat source as C++
- `link(%params)` — Link object files into a library. In scalar context returns the library name; in list returns the library and any temporary files. Required: `objects` (string or array ref). Optional:
  - `lib_file` — Output library name; defaults to `lib_file($objects->[0])`
  - `module_name` — Perl module name (required on platforms needing prelink)
  - `extra_linker_flags` — Additional linker flags
- `link_executable(%params)` — Link object files into an executable. Similar to `link` but with `exe_file` parameter (defaults to `exe_file($objects->[0])`).
- `prelink(%params)` — Perform prelinking actions (needed on Win32, OS/2, VMS, AIX). Returns list of generated files. Accepts parameters mapped to `ExtUtils::Mksymlists` options:
  - `dl_name` (required), `dl_base`, `dl_file`, `dl_vars`, `dl_funcs`, `dl_func_list`, `dl_imports`, `dl_version`.
- `need_prelink` — Returns true if platform requires `prelink()` before linking.
- `extra_link_args_after_prelink(%params)` — Returns extra linker arguments after prelink; expects a `prelink_res` key containing the prelink results array ref.

### Filename helpers
- `object_file($source_file)` — Derive object file name from a C source file (e.g., `foo.c` → `foo.o`).
- `lib_file($object_file)` — Derive library file name from an object file (e.g., `foo.o` → `foo.bundle` on macOS).
- `exe_file($object_file)` — Derive executable file name from an object file (e.g., `foo.o` → `foo` on Unix, `foo.exe` on Windows).

## Examples
perl
use ExtUtils::CBuilder;

my $builder = ExtUtils::CBuilder->new(quiet => 1);
die "No compiler" unless $builder->have_compiler;

my $obj = $builder->compile(
    source      => 'src/helper.c',
    include_dirs => ['include'],
);
my $lib = $builder->link(
    objects     => $obj,
    module_name => 'My::Module',
);
## See Also
- [Module::Build](https://www.chedong.com/phpMan.php/perldoc/Module%3A%3ABuild/markdown)
- [ExtUtils::Mksymlists](https://www.chedong.com/phpMan.php/perldoc/ExtUtils%3A%3AMksymlists/markdown)
- [Config](https://perldoc.perl.org/Config) (CPAN) – Perl configuration settings
- [perlbug](https://perldoc.perl.org/perlbug) – Reporting bugs for core modules