File: dlopen.3

package info (click to toggle)
manpages-ja 0.5.0.0.20050315-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 18,620 kB
  • ctags: 4
  • sloc: sh: 12,675; perl: 157; makefile: 106
file content (240 lines) | stat: -rw-r--r-- 7,528 bytes parent folder | download
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
.\" -*- nroff -*-
.\" Copyright 1995 Yggdrasil Computing, Incorporated.
.\" written by Adam J. Richter (adam@yggdrasil.com),
.\" with typesetting help from Daniel Quinlan (quinlan@yggdrasil.com).
.\"
.\" This is free documentation; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License as
.\" published by the Free Software Foundation; either version 2 of
.\" the License, or (at your option) any later version.
.\"
.\" The GNU General Public License's references to "object code"
.\" and "executables" are to be interpreted as the output of any
.\" document formatting or typesetting system, including
.\" intermediate and printed output.
.\"
.\" This manual is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public
.\" License along with this manual; if not, write to the Free
.\" Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
.\" USA.
.\"
.\" Modified by David A. Wheeler <dwheeler@dwheeler.com> 2000-11-28.
.\" Applied patch by Terran Melconian, aeb, 2001-12-14.
.\" Modified by Hacksaw <hacksaw@hacksaw.org> 2003-03-13.
.\"
.\" Japanese Version Copyright (c) 1998 NAKANO Takeo all rights reserved.
.\" Translated Sat May 23 1998 by NAKANO Takeo <nakano@apm.seikei.ac.jp>
.\" Updated & Modified Tue Sep 14 1999 by NAKANO Takeo 
.\"
.\" Modified Sun Mar 19 23:01:38 JST 2000
.\"         by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
.\" Updated Fri Feb 16 JST 2001 by Kentaro Shirakata <argrath@ub32.org>
.\" Updated Fri Dec 21 JST 2001 by Kentaro Shirakata <argrath@ub32.org>
.\" Updated Wed Oct 21 JST 2002 by Kentaro Shirakata <argrath@ub32.org>
.\" Updated Mon Sep  1 JST 2003 by Kentaro Shirakata <argrath@ub32.org>
.\"
.TH DLOPEN 3 2003-03-13 "Linux" "Linux Programmer's Manual"
.SH ̾
dlclose, dlerror, dlopen, dlsym \- ʥߥå󥯤ԤؤΥץߥ󥰥󥿡ե
.SH 
.B #include <dlfcn.h>
.sp
.BI "void *dlopen(const char *" filename ", int " flag );
.br
.BI "const char *dlerror(void);"
.br
.BI "void *dlsym(void *" handle ", char *" symbol );
.br
.BI "int dlclose(void *" handle );
.sp
üʥܥ:
.BR "_init" ", " "_fini"
.SH 
.B dlopen
 NUL üʸ
.I filename
ǻꤵ줿̾Υեʥߥå饤֥Ȥƥɤ
Υʥߥå饤֥
 (opaque) ʡ֥ϥɥפ֤
.\" opaque ˤĤƤ [JM:09377] 
.I filename
Хѥ ("/" ǻϤޤѥ) \fIʤ\fPˤϡե
ʲξ꤫鸡롣
.RS
.PP
桼 \fBLD_LIBRARY_PATH\fP Ķѿǻꤵ줿ڤ
ǥ쥯ȥꥹȡ
.PP
\fI/etc/ld.so.cache\fP ˤ饤֥ꡦåΥꥹȡ
.PP
\fI/lib\fP \fI/usr/lib\fP
.RE
.PP
.I filename
 NULL ݥ󥿤Ǥϡ
֤ϥɥϥᥤץΤΤˤʤ롣
.PP
ץ󤵤줿饤֥ǤγȤϡ
Υ饤֥ΰ¸ꥹȤˤ饤֥꤫Ǥ
.B RTLD_GLOBAL
ե饰ȶ˥ץ󤵤Ƥ饤֥ѤƲ褵롣
¹ԥե뤬 "-rdynamic" ե饰ȤȤ˥󥯤Ƥϡ
¹ԥեΥХ륷ܥ⡢
ʥߥå˥ɤ饤֥ؤλȲѤ롣
.PP
.I flag
ϰʲΤ줫ǤʤФʤʤ:
.B RTLD_LAZY
ϥʥߥå饤֥Υɤ¹Ԥݤ
̤ܥ缡褷ƤȤ򼨤
.B RTLD_NOW

.B dlopen
νκǸǤ٤Ƥ̤ܥ褷줬Ǥʤˤ 
dlopen ԤȤʤ뤳Ȥ򼨤
.B RTLD_GLOBAL

.I flag
 OR 黻뤳ȤǤ롣ξˤϡ饤֥Ƥ
ܥ뤬³ƥɤ¾Υ饤֥Ǥͭˤʤ롣
.PP
饤֥꤬
.B _init
Ȥ̾Υ롼򥨥ݡȤƤС dlopen λ
Υɤ¹Ԥ롣
ξ硢ȥåץեȤΥ󥯤򤱤ɬפ롣
 gcc Υޥɥ饤 "-nostartfiles" ץꤹ뤳Ȥ
¸Ǥ롣
.PP
Ʊ饤֥꤬
.B dlopen()
ˤä٥ɤ줿ˤϡƱեϥɥ뤬֤롣
dl 饤֥ϥʥߥåեϥɥΥ󥯿ݻƤ롣
äƥʥߥå饤֥
.B dlclose

.B dlopen
ƱƤӽФʤХɤʤ
.PP
.B dlopen
ϡ餫ͳǼԤ NULL ֤
dl 롼 (dlopen, dlsym, dlclose) Τ줫
Ǥᤤ顼ϡ
.B dlerror()
ˤäƿʹ֤˲ɤʷɽ뤳ȤǤ롣
.B dlerror
Ͻ줿뤤ϺǸ˸ƤӽФ줿饨顼ä
ʤ NULL ֤ (
.B dlerror()
 2 ³ƸƤӽФȡ 2 ܤΥǤɬ NULL ֤롣)
.PP
.B dlsym
 dlopen ˤä֤줿ʥߥå饤֥Ρ֥ϥɥפȡ 
̥ʸǽü줿ʸΥܥ̾˼ꡢ
Υܥ뤬ɤƤ륢ɥ쥹֤
ܥ뤬Ĥʤˤϡ
.B dlsym
 NULL ֤
.B dlsym
Υ顼Ĵ٤ˤϡ
.B dlerror
η̤ѿ¸
줬 NULL ǤʤɤåΤǤ롣
ܥͤºݤ NULL Ǥ⤢뤫Ǥ롣ޤ
.B dlerror
η̤ѿ¸ƤȤɬפʤȤǤ롣ʤʤ⤦
.B dlerror
ƤӽФȡ֤ͤ NULL ȤʤäƤޤǤ롣
.PP
.B RTLD_DEFAULT

.B RTLD_NEXT
ȤĤ̤ʵϥɥ뤬롣
ԤϥǥեȤΥ饤֥긡Ȥäơ륷ܥ뤬
ǽ˸Ȥõ
Ԥ(ʥߥå饤֥ǤΤͭѤǤ뤬)
ǸߤΥ饤֥ʹߡ˴ؿȤõ
ˤꡢ¾ζͭ饤֥δؿؤΥåѡ󶡤Ǥ롣
.PP
.B dlclose
ϥʥߥå饤֥Υϥɥ
.I handle
λȥȤ 1 餹ȥȤ 0 ˤʤꡢ¾
ɤƤ饤֥ˤäƥܥ뤬ȤƤʤС
Υʥߥå饤֥ϥɤ롣
Υʥߥå饤֥ˤä
.B _fini
Ȥ̾Υ롼󤬥ݡȤƤˤϡ
饤֥򥢥ɤľˤΥ롼󤬸ƤӽФ롣
.SH ֤
.B dlclose
 0 ֤顼λ 0 ֤
.SH 
.B math 饤֥ɤ2.0 ;ɽ
.RS
.nf
.if t .ft CW
#include <stdio.h>
#include <dlfcn.h>

int main(int argc, char **argv) {
    void *handle;
    double (*cosine)(double);
    char *error;

    handle = dlopen ("libm.so", RTLD_LAZY);
    if (!handle) {
        fprintf (stderr, "%s\en", dlerror());
        exit(1);
    }

    cosine = dlsym(handle, "cos");
    if ((error = dlerror()) != NULL)  {
        fprintf (stderr, "%s\en", error);
        exit(1);
    }

    printf ("%f\en", (*cosine)(2.0));
    dlclose(handle);
    return 0;
}
.if t .ft P
.fi
.RE
.PP
Υץ "foo.c" ˽񤤤ȤȡʲΥޥɤǥץ
ӥɤǤ롣
.RS
.LP
gcc -rdynamic -o foo foo.c -ldl
.RE
.PP
_init()  _fini() 򥨥ݡȤ饤֥ξ
ʲΤ褦ˤƥѥ뤹ɬפ롣Ȥ bar.c 򥳥ѥ뤹:
.RS
.LP
gcc -shared -nostartfiles -o bar bar.c
.RE
.SH 
ܥ RTLD_DEFAULT  RTLD_NEXT ϡ
ͽ _GNU_SOURCE ƤΤ
.I <dlfcn.h>
.SH 
dlopen 󥿡եɸ Solaris ȤˤƤ롣
.\" .SH ռ
.\" Linux  dlopen μϡ Eric Youngdale ˤäƤʤ줿
.\" ΤȤ Mitch D'Souza, David Engel, Hongjiu Lu, Andreas Schwab 
.\" Ϥä
.\" Υޥ˥奢ڡ Adam Richter 񤤤
.SH Ϣ
.BR ld (1),
.BR ld.so (8),
.BR ldconfig (8),
.BR ldd (1),
.B ld.so.info