Newsgroups: fj.lang.c
Path: galaxy.trc.rwcp.or.jp!coconuts.jaist!wnoc-tyo-news!news.join.ad.jp!aoba!akiu!katahira!yagi!athena!umehara
From: umehara@ito.ecei.tohoku.ac.jp (Masayoshi UMEHARA)
Subject: Re: dynamic link
In-Reply-To: umehara@ito.ecei.tohoku.ac.jp's message of Tue, 23 May 1995
 15: 39:37 GMT
Message-ID: <UMEHARA.95May24021530@rhea.ito.ecei.tohoku.ac.jp>
Sender: news@ecei.tohoku.ac.jp
Nntp-Posting-Host: athena
Organization: Ito Lab., Graduate School of Information Sciences, Tohoku Univ.,
	Sendai, Japan
References: <UMEHARA.95May22180906@rhea.ito.ecei.tohoku.ac.jp>
 <3pscq7$3ej@yama15.yz.yamagata-u.ac.jp>
 <UMEHARA.95May24003937@rhea.ito.ecei.tohoku.ac.jp>
Date: Tue, 23 May 1995 17:15:30 GMT
Dnas-Posting-Host: rhea.ito.ecei.tohoku.ac.jp
Lines: 61
Xref: galaxy.trc.rwcp.or.jp fj.lang.c:1885
X-originally-archived-at: http://galaxy.rwcp.or.jp/text/cgi-bin/newsarticle2?ng=fj.lang.c&nb=1885&hd=a
X-reformat-date: Mon, 18 Oct 2004 15:18:22 +0900
X-reformat-comment: Tabs were expanded into 4 column tabstops by the Galaxy's archiver. See http://katsu.watanabe.name/ancientfj/galaxy-format.html for more info.

$BG_86!wElKLBg3X$G$9!#(B

$B$I$&$d$i(Bdynamic link $B$,=PMh$?$h$&$G$9$N$G!"$4Js9p$7$^$9!#(B

$B0J2<!"(BDEC OSF/1$BMQ$N4JC1$J(Bexample$B$G$9!#(B
($B$J$<$+(BSolaris2.3$B$G$O!"(B-ldl$B$rIU$1$F$b<B9T;~(Berror$B$,=P$F$7$^$$$^$7$?!#(B)

a.c:
--------------------------------------
#include<stdio.h>

void sub(char *str)
{
    printf("This is a test.\n");
    printf("Test strings: %s\n",str);
}
--------------------------------------

b.c:
--------------------------------------
#include<stdio.h>
#include<dlfcn.h>

main()
{
    void *handle;
    void (*ptr)(char *);
    
    if((handle = dlopen("a.o", RTLD_LAZY)) == NULL)
    {
        printf("Object read error\n");
        exit(1);
    }
    
    ptr = (void (*)(char *))dlsym(handle, "sub");

    (*ptr)("Are you ready ?");

    dlclose(handle);
}
--------------------------------------

Compile: (using gcc 2.6.3)
gcc -shared -o a.o a.c
gcc b.c -o b

Execute:
b [CR]
This is a test.
Test strings: Are you ready ?


$B$3$3$^$GC)$jCe$1$?$N$b!"(Bhint$B$r2<$5$C$?$_$J$5$^$N$*$+$2$G$9!#(B
$B$"$j$,$H$&$4$6$$$^$7$?!#(B

-------------------------------------------------------------------------

 $BElKLBg3XBg3X1!(B $B>pJs2J3X8&5f2J(B $B>pJs4pAC2J3X@l96(B $B0KF#(B($B5.(B)$B8&5f<<(B 
    $BG_86(B $B@55A(B    E-mail address: umehara@ito.ecei.tohoku.ac.jp

-------------------------------------------------------------------------
