1ExtUtils::CBuilder(3) User Contributed Perl DocumentationExtUtils::CBuilder(3)
2
3
4

NAME

6       ExtUtils::CBuilder - Compile and link C code for Perl modules
7

SYNOPSIS

9         use ExtUtils::CBuilder;
10
11         my $b = ExtUtils::CBuilder->new(%options);
12         $obj_file = $b->compile(source => 'MyModule.c');
13         $lib_file = $b->link(objects => $obj_file);
14

DESCRIPTION

16       This module can build the C portions of Perl modules by invoking the
17       appropriate compilers and linkers in a cross-platform manner.  It was
18       motivated by the "Module::Build" project, but may be useful for other
19       purposes as well.  However, it is not intended as a general cross-plat‐
20       form interface to all your C building needs.  That would have been a
21       much more ambitious goal!
22

METHODS

24       new Returns a new "ExtUtils::CBuilder" object.  A "config" parameter
25           lets you override "Config.pm" settings for all operations performed
26           by the object, as in the following example:
27
28             # Use a different compiler than Config.pm says
29             my $b = ExtUtils::CBuilder->new( config =>
30                                              { ld => 'gcc' } );
31
32           A "quiet" parameter tells "CBuilder" to not print its "system()"
33           commands before executing them:
34
35             # Be quieter than normal
36             my $b = ExtUtils::CBuilder->new( quiet => 1 );
37
38       have_compiler
39           Returns true if the current system has a working C compiler and
40           linker, false otherwise.  To determine this, we actually compile
41           and link a sample C library.
42
43       compile
44           Compiles a C source file and produces an object file.  The name of
45           the object file is returned.  The source file is specified in a
46           "source" parameter, which is required; the other parameters listed
47           below are optional.
48
49           "object_file"
50               Specifies the name of the output file to create.  Otherwise the
51               "object_file()" method will be consulted, passing it the name
52               of the "source" file.
53
54           "include_dirs"
55               Specifies any additional directories in which to search for
56               header files.  May be given as a string indicating a single
57               directory, or as a list reference indicating multiple directo‐
58               ries.
59
60           "extra_compiler_flags"
61               Specifies any additional arguments to pass to the compiler.
62               Should be given as a list reference containing the arguments
63               individually, or if this is not possible, as a string contain‐
64               ing all the arguments together.
65
66           The operation of this method is also affected by the "archlibexp",
67           "cccdlflags", "ccflags", "optimize", and "cc" entries in "Con‐
68           fig.pm".
69
70       link
71           Invokes the linker to produce a library file from object files.  In
72           scalar context, the name of the library file is returned.  In list
73           context, the library file and any temporary files created are
74           returned.  A required "objects" parameter contains the name of the
75           object files to process, either in a string (for one object file)
76           or list reference (for one or more files).  The following parame‐
77           ters are optional:
78
79           lib_file
80               Specifies the name of the output library file to create.  Oth‐
81               erwise the "lib_file()" method will be consulted, passing it
82               the name of the first entry in "objects".
83
84           module_name
85               Specifies the name of the Perl module that will be created by
86               linking.  On platforms that need to do prelinking (Win32, OS/2,
87               etc.) this is a required parameter.
88
89           extra_linker_flags
90               Any additional flags you wish to pass to the linker.
91
92           On platforms where "need_prelink()" returns true, "prelink()" will
93           be called automatically.
94
95           The operation of this method is also affected by the "lddlflags",
96           "shrpenv", and "ld" entries in "Config.pm".
97
98       link_executable
99           Invokes the linker to produce an executable file from object files.
100           In scalar context, the name of the executable file is returned.  In
101           list context, the executable file and any temporary files created
102           are returned.  A required "objects" parameter contains the name of
103           the object files to process, either in a string (for one object
104           file) or list reference (for one or more files).  The optional
105           parameters are the same as "link" with exception for
106
107           exe_file
108               Specifies the name of the output executable file to create.
109               Otherwise the "exe_file()" method will be consulted, passing it
110               the name of the first entry in "objects".
111
112       object_file
113            my $object_file = $b->object_file($source_file);
114
115           Converts the name of a C source file to the most natural name of an
116           output object file to create from it.  For instance, on Unix the
117           source file foo.c would result in the object file foo.o.
118
119       lib_file
120            my $lib_file = $b->lib_file($object_file);
121
122           Converts the name of an object file to the most natural name of a
123           output library file to create from it.  For instance, on Mac OS X
124           the object file foo.o would result in the library file foo.bundle.
125
126       exe_file
127            my $exe_file = $b->exe_file($object_file);
128
129           Converts the name of an object file to the most natural name of an
130           executable file to create from it.  For instance, on Mac OS X the
131           object file foo.o would result in the executable file foo, and on
132           Windows it would result in foo.exe.
133
134       prelink
135           On certain platforms like Win32, OS/2, VMS, and AIX, it is neces‐
136           sary to perform some actions before invoking the linker.  The
137           "ExtUtils::Mksymlists" module does this, writing files used by the
138           linker during the creation of shared libraries for dynamic exten‐
139           sions.  The names of any files written will be returned as a list.
140
141           Several parameters correspond to "ExtUtils::Mksymlists::Mksym‐
142           lists()" options, as follows:
143
144               Mksymlists()   prelink()          type
145              -------------⎪-------------------⎪-------------------
146               NAME        ⎪  dl_name          ⎪ string (required)
147               DLBASE      ⎪  dl_base          ⎪ string
148               FILE        ⎪  dl_file          ⎪ string
149               DL_VARS     ⎪  dl_vars          ⎪ array reference
150               DL_FUNCS    ⎪  dl_funcs         ⎪ hash reference
151               FUNCLIST    ⎪  dl_func_list     ⎪ array reference
152               IMPORTS     ⎪  dl_imports       ⎪ hash reference
153               VERSION     ⎪  dl_version       ⎪ string
154
155           Please see the documentation for "ExtUtils::Mksymlists" for the
156           details of what these parameters do.
157
158       need_prelink
159           Returns true on platforms where "prelink()" should be called during
160           linking, and false otherwise.
161
162       extra_link_args_after_prelink
163           Returns list of extra arguments to give to the link command; the
164           arguments are the same as for prelink(), with addition of array
165           reference to the results of prelink(); this reference is indexed by
166           key "prelink_res".
167

TO DO

169       Currently this has only been tested on Unix and doesn't contain any of
170       the Windows-specific code from the "Module::Build" project.  I'll do
171       that next.
172

HISTORY

174       This module is an outgrowth of the "Module::Build" project, to which
175       there have been many contributors.  Notably, Randy W. Sims submitted
176       lots of code to support 3 compilers on Windows and helped with various
177       other platform-specific issues.  Ilya Zakharevich has contributed fixes
178       for OS/2; John E. Malmberg and Peter Prymmer have done likewise for
179       VMS.
180

AUTHOR

182       Ken Williams, kwilliams@cpan.org
183
185       Copyright (c) 2003-2005 Ken Williams.  All rights reserved.
186
187       This library is free software; you can redistribute it and/or modify it
188       under the same terms as Perl itself.
189

SEE ALSO

191       perl(1), Module::Build(3)
192
193
194
195perl v5.8.8                       2006-03-25             ExtUtils::CBuilder(3)
Impressum