home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 20067 < prev    next >
Encoding:
Text File  |  1993-01-28  |  1.5 KB  |  65 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!math.fu-berlin.de!ira.uka.de!scsing.switch.ch!univ-lyon1.fr!ghost.dsi.unimi.it!rpi!uwm.edu!linac!att!cbnewsc!cbfsb!cbnewsg.cb.att.com!nh
  3. From: nh@cbnewsg.cb.att.com (nicholas.hounsome)
  4. Subject: Re: Dynamic Linking and Sun Sparcs, do they mix?
  5. Message-ID: <1993Jan28.091112.3088@cbfsb.cb.att.com>
  6. Sender: news@cbfsb.cb.att.com
  7. Organization: AT&T
  8. References: <1993Jan27.192131.14505@ucc.su.OZ.AU>
  9. Date: Thu, 28 Jan 1993 09:11:12 GMT
  10. Lines: 53
  11.  
  12. I have started to investigate DLLs on the sun and all seems to work 
  13. as expected.
  14.  
  15. This was my first test program which incidentaly gives me some good ideas for
  16. a simple config file reader or debugging interface:
  17.  
  18. #include <stdio.h>
  19. #include <dlfcn.h>
  20. int a()
  21. {
  22.     printf("a called\n");
  23. }
  24.  
  25. int b()
  26. {
  27.     printf("b called\n");
  28. }
  29.  
  30. main()
  31. {
  32.     char buf[200];
  33.     void *handle;
  34.     void *handle2;
  35.     void *handle3;
  36.     int (*f)();
  37.     handle = dlopen(NULL,1);
  38.     handle2 = dlopen("/usr/lib/libc.so.1.7",1);
  39.     handle3 = dlopen("/usr/openwin/lib/libX11.so.4.3",1);
  40.     while(gets(buf))
  41.     {
  42.         f = dlsym(handle,buf);
  43.         if( f )
  44.             f(buf) ;
  45.         else
  46.         {
  47.             f = dlsym(handle2,buf);
  48.             if( f )
  49.                 f("called %s\n",buf) ;
  50.             else
  51.             {
  52.                 f = dlsym(handle3,buf);
  53.                 if( f )
  54.                     f("called %s\n",buf) ;
  55.                 else
  56.                 {
  57.                     printf("no function %s\n", buf);
  58.                 }
  59.             }
  60.         }
  61.     }
  62. }
  63.  
  64. Nick Hounsome
  65.