1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
.\" -*- mode: troff; coding: utf-8 -*-
.\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
.ie n \{\
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "ExtUtils::Embed 3perl"
.TH ExtUtils::Embed 3perl 2024-05-30 "perl v5.38.2" "Perl Programmers Reference Guide"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH NAME
ExtUtils::Embed \- Utilities for embedding Perl in C/C++ applications
.SH SYNOPSIS
.IX Header "SYNOPSIS"
.Vb 3
\& perl \-MExtUtils::Embed \-e xsinit
\& perl \-MExtUtils::Embed \-e ccopts
\& perl \-MExtUtils::Embed \-e ldopts
.Ve
.SH DESCRIPTION
.IX Header "DESCRIPTION"
\&\f(CW\*(C`ExtUtils::Embed\*(C'\fR provides utility functions for embedding a Perl interpreter
and extensions in your C/C++ applications.
Typically, an application \fIMakefile\fR will invoke \f(CW\*(C`ExtUtils::Embed\*(C'\fR
functions while building your application.
.PP
Note that on Debian systems the \fBlibperl-dev\fR package is required for
compiling applications which embed an interpreter.
.ie n .SH @EXPORT
.el .SH \f(CW@EXPORT\fP
.IX Header "@EXPORT"
\&\f(CW\*(C`ExtUtils::Embed\*(C'\fR exports the following functions:
.PP
\&\fBxsinit()\fR, \fBldopts()\fR, \fBccopts()\fR, \fBperl_inc()\fR, \fBccflags()\fR,
\&\fBccdlflags()\fR, \fBxsi_header()\fR, \fBxsi_protos()\fR, \fBxsi_body()\fR
.SH FUNCTIONS
.IX Header "FUNCTIONS"
.IP \fBxsinit()\fR 4
.IX Item "xsinit()"
Generate C/C++ code for the XS initializer function.
.Sp
When invoked as \f(CW\`perl \-MExtUtils::Embed \-e xsinit \-\-\`\fR
the following options are recognized:
.Sp
\&\fB\-o\fR <output filename> (Defaults to \fBperlxsi.c\fR)
.Sp
\&\fB\-o STDOUT\fR will print to STDOUT.
.Sp
\&\fB\-std\fR (Write code for extensions that are linked with the current Perl.)
.Sp
Any additional arguments are expected to be names of modules
to generate code for.
.Sp
When invoked with parameters the following are accepted and optional:
.Sp
\&\f(CW\*(C`xsinit($filename,$std,[@modules])\*(C'\fR
.Sp
Where,
.Sp
\&\fR\f(CB$filename\fR\fB\fR is equivalent to the \fB\-o\fR option.
.Sp
\&\fR\f(CB$std\fR\fB\fR is boolean, equivalent to the \fB\-std\fR option.
.Sp
\&\fB[@modules]\fR is an array ref, same as additional arguments mentioned above.
.IP Examples 4
.IX Item "Examples"
.Vb 1
\& perl \-MExtUtils::Embed \-e xsinit \-\- \-o xsinit.c Socket
.Ve
.Sp
This will generate code with an \f(CW\*(C`xs_init\*(C'\fR function that glues the perl \f(CW\*(C`Socket::bootstrap\*(C'\fR function
to the C \f(CW\*(C`boot_Socket\*(C'\fR function and writes it to a file named \fIxsinit.c\fR.
.Sp
Note that DynaLoader is a special case where it must call \f(CW\*(C`boot_DynaLoader\*(C'\fR directly.
.Sp
.Vb 1
\& perl \-MExtUtils::Embed \-e xsinit
.Ve
.Sp
This will generate code for linking with \f(CW\*(C`DynaLoader\*(C'\fR and
each static extension found in \f(CW$Config{static_ext}\fR.
The code is written to the default file name \fIperlxsi.c\fR.
.Sp
.Vb 2
\& perl \-MExtUtils::Embed \-e xsinit \-\- \-o xsinit.c \e
\& \-std DBI DBD::Oracle
.Ve
.Sp
Here, code is written for all the currently linked extensions along with code
for \f(CW\*(C`DBI\*(C'\fR and \f(CW\*(C`DBD::Oracle\*(C'\fR.
.Sp
If you have a working \f(CW\*(C`DynaLoader\*(C'\fR then there is rarely any need to statically link in any
other extensions.
.IP \fBldopts()\fR 4
.IX Item "ldopts()"
Output arguments for linking the Perl library and extensions to your
application.
.Sp
When invoked as \f(CW\`perl \-MExtUtils::Embed \-e ldopts \-\-\`\fR
the following options are recognized:
.Sp
\&\fB\-std\fR
.Sp
Output arguments for linking the Perl library and any extensions linked
with the current Perl.
.Sp
\&\fB\-I\fR <path1:path2>
.Sp
Search path for ModuleName.a archives.
Default path is \f(CW@INC\fR.
Library archives are expected to be found as
\&\fI/some/path/auto/ModuleName/ModuleName.a\fR
For example, when looking for \fISocket.a\fR relative to a search path,
we should find \fIauto/Socket/Socket.a\fR
.Sp
When looking for \f(CW\*(C`DBD::Oracle\*(C'\fR relative to a search path,
we should find \fIauto/DBD/Oracle/Oracle.a\fR
.Sp
Keep in mind that you can always supply \fI/my/own/path/ModuleName.a\fR
as an additional linker argument.
.Sp
\&\fB\-\-\fR <list of linker args>
.Sp
Additional linker arguments to be considered.
.Sp
Any additional arguments found before the \fB\-\-\fR token
are expected to be names of modules to generate code for.
.Sp
When invoked with parameters the following are accepted and optional:
.Sp
\&\f(CW\*(C`ldopts($std,[@modules],[@link_args],$path)\*(C'\fR
.Sp
Where:
.Sp
\&\fR\f(CB$std\fR\fB\fR is boolean, equivalent to the \fB\-std\fR option.
.Sp
\&\fB[@modules]\fR is equivalent to additional arguments found before the \fB\-\-\fR token.
.Sp
\&\fB[@link_args]\fR is equivalent to arguments found after the \fB\-\-\fR token.
.Sp
\&\fR\f(CB$path\fR\fB\fR is equivalent to the \fB\-I\fR option.
.Sp
In addition, when ldopts is called with parameters, it will return the argument string
rather than print it to STDOUT.
.IP Examples 4
.IX Item "Examples"
.Vb 1
\& perl \-MExtUtils::Embed \-e ldopts
.Ve
.Sp
This will print arguments for linking with \f(CW\*(C`libperl\*(C'\fR and
extensions found in \f(CW$Config{static_ext}\fR. This includes libraries
found in \f(CW$Config{libs}\fR and the first ModuleName.a library
for each extension that is found by searching \f(CW@INC\fR or the path
specified by the \fB\-I\fR option.
In addition, when ModuleName.a is found, additional linker arguments
are picked up from the \fIextralibs.ld\fR file in the same directory.
.Sp
.Vb 1
\& perl \-MExtUtils::Embed \-e ldopts \-\- \-std Socket
.Ve
.Sp
This will do the same as the above example, along with printing additional
arguments for linking with the \f(CW\*(C`Socket\*(C'\fR extension.
.Sp
.Vb 2
\& perl \-MExtUtils::Embed \-e ldopts \-\- \-std Msql \-\- \e
\& \-L/usr/msql/lib \-lmsql
.Ve
.Sp
Any arguments after the second '\-\-' token are additional linker
arguments that will be examined for potential conflict. If there is no
conflict, the additional arguments will be part of the output.
.IP \fBperl_inc()\fR 4
.IX Item "perl_inc()"
For including perl header files this function simply prints:
.Sp
.Vb 1
\& \-I$Config{archlibexp}/CORE
.Ve
.Sp
So, rather than having to say:
.Sp
.Vb 1
\& perl \-MConfig \-e \*(Aqprint "\-I$Config{archlibexp}/CORE"\*(Aq
.Ve
.Sp
Just say:
.Sp
.Vb 1
\& perl \-MExtUtils::Embed \-e perl_inc
.Ve
.IP "\fBccflags()\fR, \fBccdlflags()\fR" 4
.IX Item "ccflags(), ccdlflags()"
These functions simply print \f(CW$Config\fR{ccflags} and \f(CW$Config\fR{ccdlflags}
.IP \fBccopts()\fR 4
.IX Item "ccopts()"
This function combines \f(CWperl_inc()\fR, \f(CWccflags()\fR and \f(CWccdlflags()\fR into one.
.IP \fBxsi_header()\fR 4
.IX Item "xsi_header()"
This function simply returns a string defining the same \f(CW\*(C`EXTERN_C\*(C'\fR macro as
\&\fIperlmain.c\fR along with #including \fIperl.h\fR and \fIEXTERN.h\fR.
.IP xsi_protos(@modules) 4
.IX Item "xsi_protos(@modules)"
This function returns a string of \f(CW\*(C`boot_$ModuleName\*(C'\fR prototypes for each \f(CW@modules\fR.
.IP xsi_body(@modules) 4
.IX Item "xsi_body(@modules)"
This function returns a string of calls to \f(CWnewXS()\fR that glue the module \fIbootstrap\fR
function to \fIboot_ModuleName\fR for each \f(CW@modules\fR.
.Sp
\&\f(CWxsinit()\fR uses the xsi_* functions to generate most of its code.
.SH EXAMPLES
.IX Header "EXAMPLES"
For examples on how to use \f(CW\*(C`ExtUtils::Embed\*(C'\fR for building C/C++ applications
with embedded perl, see perlembed.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
perlembed
.SH AUTHOR
.IX Header "AUTHOR"
Doug MacEachern <\f(CW\*(C`dougm@osf.org\*(C'\fR>
.PP
Based on ideas from Tim Bunce <\f(CW\*(C`Tim.Bunce@ig.co.uk\*(C'\fR> and
\&\fIminimod.pl\fR by Andreas Koenig <\f(CW\*(C`k@anna.in\-berlin.de\*(C'\fR> and Tim Bunce.
|