|
このページは大阪弁化フィルタによって翻訳生成されたんですわ。 |
A magyar ford?疽t Szalai Ferenc Attila k駸z?ette (2003.12.11). A lektor疝疽t Magyar Linux Dokument當i? Projekt honlapj疣.
A statikus programk?yvt疵ak k??s馮es t疵gyk?-f疔lok gy?tem駭yei. t疵gyk?-f疔lokat a my_library.a statikus programk?yvt疵hoz. L騁rehozza a my_library.a f疔lt, ha az nem l騁ezett. Tov畸bi inform當i?at a statikus programk?yvt疵ak k駸z?駸駻? az ar(1)-ben tal疝sz.
3. Megosztott programk?yvt疵ak
Megosztott programk?yvt疵ak olyan programk?yvt疵ak, amiket a program indul疽akor t?t be. Ha a megosztott programk?yvt疵ak megfelel?n vannak telep?ve, az ?szes program az indul疽a ut疣 automatikusan ? megosztott programk?yvt疵at haszn疝. Ez enn駘 egy kicsit rugalmasabb 駸 bonyolultabb jelenleg, mert a linuxos megold疽 megengedi azt is, hogy:
friss?sd a programk?yvt疵aidat 駸 k?ben t疥ogasd azokat a 駻tened, hogy hova kell elhelyezni ezeket a programk?yvt疵akat a f疔lrendszerben.
Minden megosztott programk?yvt疵nak van egy speci疝is neve, amit "so-n騅"-nek h?nak. >Minden megosztott programk?yvt疵nak van "val?i neve" is, ami annak az f疔lnak a neve, ami a jelenlegi programk?yvt疵 k?j疸 tartalmazza. A val?i n騅 az so-n騅hez ad egy pontot, a minor sz疥ot, egy ?abb pont-ot 駸 a >Az ldconfig nem 疝l?ja be a szerkeszt駸i neveket, 疝tal畸an ez megt?t駭t m疵 a programk?yvt疵 telep?駸e sor疣, a szerkeszt駸i n騅 egyszer?n egy szimbolikus hivatkoz疽 a "leg?abb" so-n騅re vagy a leg?abb val?i n騅re. Az tan當soln疥 legyen a csatol疽i n騅 egy szimbolikus hivatkoz疽 az so-n騅re, mivel a legt?b esetben a friss?ett programk?yvt疵at szeretn馘 automatikusan haszn疝ni, mikor csatolod azt a programodhoz. Megk駻deztem H. J,. Lu-t, mi駻t nem 疝l?ja be automatikusan az ldconfig a szerkeszt駸i neveket. A magyar痙ata alapvet?n az volt, hogy tal疣 a programk?yvt疵 legut?bi verzi?疸 szeretn馘 futtatni a k?dal, de az is lehet, hogy egy fejleszt? v疝tozatra szeretn駘 hivatkoz疽t egy r馮i - tal疣 inkompatibilis - programk?yvt疵 helyett. > egy teljes so-n騅, amit az ldconfig k駸z?ett, p駘d疼l mint szimbolikus hivatkoz疽t a /usr/lib/libreadline.so.3.0 f疔lra. Kellene lennie egy /usr/lib/libreadline.so szerkeszt駸i n騅nek is, ami egy szimbolikus hivatkoz疽 lehet a /usr/lib/libreadline.so.3 f疔lra.
Nincs igaz疣 ellentmond疽 a k騁 dokumentum k??t. A GNU szabv疣yok a fejleszt?nek, m? az FHS a terjeszt駸t ?sze疝l??nak az alap駻telmezett programk?yvt疵-keres駸i ?vonalban (l疽d a megjegyz駸eket az /etc/ld.so.conf f疔lr? lejjebb). Egy m疽ik szokv疣yos programk?yvt疵-hely az /usr/X11R6/lib, ahova az X-winodows rendszerrel kapcsolatos programk?yvt疵akat szok疽 elhelyezni. konvenci?at fogj疚 k?etni), 駸 egy gyorst疵-f疔lt k駸z? /etc/ld.so.cache n騅en. Ezt a gyorst疵at haszn疝ja azt疣 a t?bi program. Ez nagyon felgyors?ja a programk?yvt疵ak el駻駸騁. A k?etkezm駭y az, hogy az ldconfig parancsot minden esetben futtatni kell, ha ? DLL-at adunk a rendszerhez vagy ha elt疱ol?juk azt, vagy mikor 疸疝l?juk a DLL programk?yvt疵akat. Az ldconfig futtat疽 a leggyakoribb feladat, amit egy csomagkezel?ek el kell v馮eznie, mikor programk?yvt疵at telep?. ezekr? a k?nyezeti v疝toz?r?.
A felhaszn疝? beavatkoz疽 enged駘yez駸e a dinamikusan csatolt programk?yvt疵ak bet?t駸駭駘 katasztrof疝is eredm駭yre vezethet, setuid/setgid-es programok WIDTH="100%" >
gcc -shared -Wl,-soname,your_soname \
-o library_name file_list library_listヘme egy p駘da, ami k騁 t疵gyk?-f疔lt k駸z? (a.o 駸 b.o) azt疣 ezekb? egy adott programra. A gcc-t az rpath opci?al az al畸bi m?on haszn疝hatod:
-Wl,-rpath,$(DEFAULT_LIB_INSTALL_PATH) |
Ha m疵 k駸z?ett駘 megosztott programk?yvt疵at, nyilv疣 haszn疝ni is akarod. Az egyik lehet?馮, hogy egyszer?n a szabv疣yos k?yvt疵ak egyik饕e m疽olod a programk?yvt疵at (pl. /usr/lib) 駸 lefuttatod a ldconfig(8)-ot.
El?z? is k駸z?ened kell egy megosztott programk?yvt疵at valahol. WIDTH="100%" >
ldconfig -n directory_with_shared_libraries
LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH my_program |
K駻lek ne haszn疝d ezt, amikor a saj疸 programodat k駸z?ed. Pr?疝j programmal kaphatod meg. Teh疸 p駘d疼l, ha az ls program 疝tal haszn疝t megosztott programk?yvt疵akat szeretn馘 l疸ni, ?d a k?etkez?:
/lib/ld-linux.so.N (ahol N 1 vagy t?b, rendszerint legal畸b 2). Ez a programk?yvt疵 ami bet?ti az ?szes t?bit. libc.so.N (ahol N 6 vagy t?b). Ez a C programk?yvt疵. Minden m疽 nyelv is igyekszik a C programk?yvt疵at haszn疝ni (ahelyett, hogy saj疸ot val??ana meg), ?y a legt?b program legal畸b ezt az egyet haszn疝ja. Troll Tech's Technical FAQ alapj疣 ?sze疝l?ott (feltehet?eg hi疣yos) list疔a azoknak a dolgoknak, amit C felhaszn疝oknak a <dlfcn.h> header f疔lt kell beszerkeszteni (include) ennek az API-nak a haszn疝at疉oz. Az interf駸z haszn疝ata Linuxon alapvet?n ugyanolyan mint Solaris-on, amit "dlopen()" API-nak fogok h?ni. T?bet tudhatsz meg a glib-r? a http://developer.gnome.org/doc/API/glib/glib-dynamic-loading-of-modules.html honlapon. Mivel a glib interf駸z j? dokument疝t nem r駸zletezem itt. Egy m疽ik lehet?馮 a libltdl haszn疝ata, ami r駸ze a GNU libtool-nak. C protot?usa az al畸bi:
|
A dlopen() p疵ja a dlclose(), ami bez疵ja a DL programk?yvt疵at. A DL programk?yvt疵 kapcsolatsz疥l疝?at (link counts) hoz l騁re a dinamikus f疔lkezel?h?, ?y a dinamikus programk?yvt疵 mindaddig nem lesz felszabad?va, am? a dlclose-t nem h?t疚 meg annyiszor, ah疣yszor a dlopen-t. NAME="DL-LIBRARY-EXAMPLE">4.5. DL programk?yvt疵 p駘da
ヘme egy p駘da a dlopen(3) k騷ik?yvb?. Ez a p駘da bet?ti a math programk?yvt疵at 駸 ki?ja a 2.0 koszinusz疸. Ellen?zi a hib疚at, minden l駱駸n駘 (ami melegen aj疣lott):
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
int main(int argc, char **argv) {
void *handle;
double (*cosine)(double);
char *error;
handle = dlopen ("/lib/libm.so.6", 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);
} |
Ha ez a program a "foo.c" 疝lom疣yban van, akkor az al畸bi paranccsal ford?hatod le:
gcc -o foo foo.c -ldl |
Az nm(1) utas?疽 megmutatja milyen szimb?umok tal疝hat?k egy adott programk?yvt疵ban. Mind statikus, mind megosztott programk?yvt疵akra m??ik. Egy adott programk?yvt疵ra az nm(1) a szimb?umok neveit, 駸 minden szimb?um t?us疸 駸 駻t駝騁 k駱es megmutatni. Azt is k駱es meghat疵ozni, hogy a forr疽k?ban hol volt a szimb?um WIDTH="100%" >
nm -o /lib/* /usr/lib/* /usr/lib/*/* \
/usr/local/lib/* 2> /dev/null | grep 'cos$' A megosztott programk?yvt疵akat tilos a gcc "-nostartfiles" vagy "-nostdlib" kapcsol?val ford?ani. Ha ezeket haszn疝juk a konstruktor/destruktor (dlclose() megh?疽疱al, amikor az a referencia sz疥l? 0-ra 疝l?ja vagy a program norm疝is kil駱駸ekor). A C protot?usok:
void _init(void); void _fini(void); |
/* GNU ld script Use the shared library, but some functions are only in the static library, so try that secondarily. */ GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a ) |
Tov畸bi inform當i? tal疝sz err? a ld texinfo dokument當i?畸an a (Typically references to external functions are bound on an as-needed basis, and are not all bound when the application starts up.) Ha a megosztott programk?yvt疵 r馮i, az ig駭yelt interf駸ze hi疣yozhat, amikor az alkalmaz疽 megpr?疝ja haszn疝ni azt. Ez azonnali 駸 v疵atlan hib疸 okozhat.
http://www.gnu.org/manual/ld-2.9.1/html_node/ld_25.html honlapon.
Ha olyan alkalmaz疽t k駸z?esz amit t?b rendszerre szeretn駘 haszn疝ni, akkor javasolt a GNU libtool
/* Explain here what foobar does */
#ifndef FOOBAR_H
#define FOOBAR_H
#ifdef __cplusplus
extern "C" {
#endif
... header code for foobar goes here ...
#ifdef __cplusplus
}
#endif
#endifA Linux Standard Base (LSB) projekt c駘ja, hogy olyan szabv疣yokat dolgozzon ki HREF="http://www.yansite.jp/osaka2.cgi?URL=http://www-106.ibm.com/developerworks/linux/library/l-lsb.html?t=gr,lnxw02=LSBapps" TARGET="_top" >Developing LSB-certified applications: Five steps to binary-compatible Linux applications. Term駸zetesen a k?ot ?y kell meg?ni, hogy egy standardiz疝t r騁eget >
$ lsbappchk myapplication
Az al畸bi p駘d疚 mindh疵om programk?yvt疵 t?ussal foglalkoznak (statikus, megosztott 駸 dinamikus programk?yvt疵ak). A libhello.c f疔l egy trivi疝is programk?yvt疵, a libhello.h header-rel. A demo_use.c f疔l egy trivi疝is program, ami a programk?yvt疵at haszn疝ja. Ezt k?etik a dokument疝t szkriptek (script_static 駸 script_dynamic), amik bemutatj疚, hogyan haszn疝hatod a programk?yvt疵at megosztott illetve statikus programk?yvt疵k駭t. Ezut疣 a demo_dynamic.c f疔ljal 駸 a script_dynamic szkripttel megmutatjuk, COLOR="#000000" >
/* libhello.c - demonstrate library use. */
#include <stdio.h>
void hello(void) {
printf("Hello, library world.\n");
}
/* demo_use.c -- demonstrate direct use of the "hello" routine */
#include "libhello.h"
int main(void) {
hello();
return 0;
} |
#!/bin/sh # Static library demo # Create static library's object file, libhello-static.o. # I'm using the name libhello-static to clearly # differentiate the static library from the # dynamic library examples, but you don't need to use # "-static" in the names of your # object files or static libraries. gcc -Wall -g -c -o libhello-static.o libhello.c # Create static library. ar rcs libhello-static.a libhello-static.o # At this point we could just copy libhello-static.a # somewhere else to use it. # For demo purposes, we'll just keep the library # in the current directory. # Compile demo_use program file. gcc -Wall -g -c demo_use.c -o demo_use.o # Create demo_use program; -L. causes "." to be searched during # creation of the program. Note that this command causes # the relevant object file in libhello-static.a to be # incorporated into file demo_use_static. gcc -g -o demo_use_static demo_use.o -L. -lhello-static # Execute the program. ./demo_use_static |
#!/bin/sh
# Shared library demo
# Create shared library's object file, libhello.o.
gcc -fPIC -Wall -g -c libhello.c
# Create shared library.
# Use -lc to link it against C library, since libhello
# depends on the C library.
gcc -g -shared -Wl,-soname,libhello.so.0 \
-o libhello.so.0.0 libhello.o -lc
# At this point we could just copy libhello.so.0.0 into
# some directory, say /usr/local/lib.
# Now we need to call ldconfig to fix up the symbolic links.
# Set up the soname. We could just execute:
# ln -sf libhello.so.0.0 libhello.so.0
# but let's let ldconfig figure it out.
/sbin/ldconfig -n .
# Set up the linker name.
# In a more sophisticated setting, we'd need to make
# sure that if there was an existing linker name,
# and if so, check if it should stay or not.
ln -sf libhello.so.0 libhello.so
# Compile demo_use program file.
gcc -Wall -g -c demo_use.c -o demo_use.o
# Create program demo_use.
# The -L. causes "." to be searched during creation
# of the program; note that this does NOT mean that "."
# will be searched when the program is executed.
gcc -g -o demo_use demo_use.o -L. -lhello
# Execute the program. Note that we need to tell the program
# where the shared library is, using LD_LIBRARY_PATH.
LD_LIBRARY_PATH="." ./demo_use
|
/* demo_dynamic.c -- demonstrate dynamic loading and
use of the "hello" routine */
/* Need dlfcn.h for the routines to
dynamically load libraries */
#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>
/* Note that we don't have to include "libhello.h".
However, we do need to specify something related;
we need to specify a type that will hold the value
we're going to get from dlsym(). */
/* The type "simple_demo_function" describes a function that
takes no arguments, and returns no value: */
typedef void (*simple_demo_function)(void);
int main(void) {
const char *error;
void *module;
simple_demo_function demo_function;
/* Load dynamically loaded library */
module = dlopen("libhello.so", RTLD_LAZY);
if (!module) {
fprintf(stderr, "Couldn't open libhello.so: %s\n",
dlerror());
exit(1);
}
/* Get symbol */
dlerror();
demo_function = dlsym(module, "hello");
if ((error = dlerror())) {
fprintf(stderr, "Couldn't find hello: %s\n", error);
exit(1);
}
/* Now call the function in the DL library */
(*demo_function)();
/* All done, close things cleanly */
dlclose(module);
return 0;
} |
#!/bin/sh # Dynamically loaded library demo # Presume that libhello.so and friends have # been created (see dynamic example). # Compile demo_dynamic program file into an object file. gcc -Wall -g -c demo_dynamic.c # Create program demo_use. # Note that we don't have to tell it where to search for DL libraries, # since the only special library this program uses won't be # loaded until after the program starts up. # However, we DO need the option -ldl to include the library # that loads the DL libraries. gcc -g -o demo_dynamic demo_dynamic.o -ldl # Execute the program. Note that we need to tell the # program where get the dynamically loaded library, # using LD_LIBRARY_PATH. LD_LIBRARY_PATH="." ./demo_dynamic |
Tool Interface Standards (TIS) biztos疊: "Executable and Linkable Format (ELF)" (ez jelenleg egy fejezete a Portable Formats Specification Version 1.1.-nek ugyanett? a bizotts疊t?). CLASS="SECT1" >
This document is Copyright (C) 2000 David A. Wheeler.
It is covered by the GNU General Public License (GPL).
You may redistribute it without cost.
Interpret the document's source text
as the ``program'' and adhere to the following terms:
This program is free software; 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. This program 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 program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
These terms do permit mirroring by other web sites, but please:
make sure your mirrors automatically get upgrades from the master site,
clearly show the location of the master site, http://www.dwheeler.com/program-library, with a hypertext link to the master site, and
give me (David A. Wheeler) credit as the author.
The first two points primarily protect me from repeatedly hearing about obsolete bugs. I do not want to hear about bugs I fixed a year ago, just because you are not properly mirroring the document. By linking to the master site, users can check and see if your mirror is up-to-date. I'm sensitive to the problems of sites which have very strong security requirements and therefore cannot risk normal connections to the Internet; if that describes your situation, at least try to meet the other points and try to occasionally sneakernet updates into your environment.
By this license, you may modify the document, but you can't claim that what you didn't write is yours (i.e., plagiarism) nor can you pretend that a modified version is identical to the original work. Modifying the work does not transfer copyright of the entire work to you; this is not a ``public domain'' work in terms of copyright law. See the license for details, in particular noting that ``You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.'' If you have questions about what the license allows, please contact me. In most cases, it's better if you send your changes to the master integrator (currently David A. Wheeler), so that your changes will be integrated with everyone else's changes into the master copy.