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
|
.\" -*- 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.
.\"
.\" 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
.\"
.TH DLOPEN 3 "16 May 1995" "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 dladdr(void *"address ", Dl_info *"dlip ");"
.br
.BI "int dlclose (void *"handle ");
.sp
üʥܥ:
.BR "_init" ", " "_fini" ". "
.SH
.B dlopen
null üʸ
.I filename
ǻꤵ줿̾Υեʥߥå饤֥Ȥƥɤ
Υʥߥå饤֥
Ʃ (opaque) ʡ֥ϥɥפ֤
.\"?? opaque ϥɥ?
.I filename
Хѥ ("/" ǻϤޤѥ) \fIʤ\fPˤϡե
ϰʲξ꤫鸡롣
.RS
.PP
桼 \fBLD_LIBRARY\fP Ķѿǻꤵ줿ڤΥǥ
쥯ȥꥹȡ
.PP
\fI/etc/ld.so.cache\fP ˤ饤֥Υꥹȡ
.PP
\fI/usr/lib\fP \fI/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 λˤ
Υɤ¹Ԥ롣Ʊ饤֥꤬
.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 dladdr
ϡ
.I address
ǻꤵ줿֤ͭƤ붦ͭ饤֥˴ؤ֤
.B dladdr
ȥԤ֤ͤ
.PP
.B dlclose
ϥʥߥå饤֥Υϥɥ
.I handle
λȥȤ 1 餹ȥȤ 0 ˤʤꡢ¾ǥɤƤ
饤֥ˤäƥܥ뤬ȤƤʤСΥʥߥå饤
֥ϥɤ롣Υʥߥå饤֥ˤä
.B _fini
Ȥ̾Υ롼ݡȤƤˤϡ
饤֥ɤľˤΥ롼ƤӽФ롣
.SH
.B math 饤֥ɤ2.0 ;ɽ롣
.RS
.nf
.if t .ft CW
#include <dlfcn.h>
int main(int argc, char **argv) {
void *handle = dlopen ("/lib/libm.so", RTLD_LAZY);
double (*cosine)(double) = dlsym(handle, "cos");
printf ("%f\\n", (*cosine)(2.0));
dlclose(handle);
}
.if t .ft P
.fi
.PP
Υץ "foo.c" ˽ȤȡʲΥޥɤǥץ
ӥɤ뤳ȤǤ롣
.RS
.LP
gcc -rdynamic -o foo foo.c -ldl
.RE
.RE
.LP
.B ƱȤƤ뤬٤Ƥʳǥ顼åԤäƤ:
.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 ("/lib/libm.so", RTLD_LAZY);
if (!handle) {
fputs (dlerror(), stderr);
exit(1);
}
cosine = dlsym(handle, "cos");
if ((error = dlerror()) != NULL) {
fputs(error, stderr);
exit(1);
}
printf ("%f\\n", (*cosine)(2.0));
dlclose(handle);
}
.if t .ft P
.fi
.RE
.SH ռ
dlopen եɸ Solaris ȤˤƤ롣
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)
|