home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / unix / programm / 5316 < prev    next >
Encoding:
Text File  |  1992-11-17  |  2.2 KB  |  90 lines

  1. Xref: sparky comp.unix.programmer:5316 comp.sys.sun.misc:5303 comp.unix.solaris:324
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!sdd.hp.com!elroy.jpl.nasa.gov!usc!news.service.uci.edu!ucivax!schmidt
  3. From: schmidt@net1.ics.uci.edu (Douglas C. Schmidt)
  4. Subject: Dynamic linking on Sun OS
  5. Nntp-Posting-Host: net1.ics.uci.edu
  6. Message-ID: <2B0947EA.4501@ics.uci.edu>
  7. Newsgroups: comp.unix.programmer,comp.sys.sun.misc,comp.unix.solaris
  8. Reply-To: schmidt@ics.uci.edu (Douglas C. Schmidt)
  9. Organization: University of California at Irvine: ICS Dept.
  10. Lines: 77
  11. Date: 17 Nov 92 19:28:43 GMT
  12.  
  13. Hi,
  14.  
  15.     I've been experiementing with dynamic linking via Sun OS 4.1.2.
  16. However, I'm having the following problem when I try to use the
  17. dlopen(), dlsym() library:
  18.  
  19. % ./a.out ~/tmp/x1.o _foo
  20. ld.so: mmap data error (22) for /i0/da/ud/schmidt/tmp/x1.o
  21.  
  22. The main program looks like this:
  23.  
  24. ----------------------------------------
  25. #include <stdio.h>
  26. #include <dlfcn.h>
  27.  
  28. int
  29. main (argc, argv)
  30.      int argc;
  31.      char *argv[];
  32. {
  33.   char *path = argv[1];
  34.   char *symbol = argv[2];
  35.   void *handle;
  36.   int (*f)(void);
  37.  
  38.   if ((handle = dlopen (path, 1)) == 0)
  39.     dlerror ("dlopen failed");
  40.  
  41.   fprintf (stderr, "handle = %d\n", handle);
  42.  
  43.   if ((f = (int (*)(void)) dlsym (handle, symbol)) == (int (*)(void)) 0)
  44.     dlerror ("dlsym failed");
  45.  
  46.   fprintf (stderr, "f = %d\n", f);
  47.  
  48.   if (f != 0)
  49.     (*f)();
  50.   else
  51.     fprintf (stderr, "symbol %s not found\n", symbol);
  52.   dlclose (handle);
  53. }
  54. ----------------------------------------
  55.  
  56. The x1.c file looks like this:
  57.  
  58. ----------------------------------------
  59. #include <stdio.h>
  60.  
  61. void
  62. init ()
  63. {
  64.   fprintf (stderr, "starting x1\n");
  65. }
  66.  
  67. int
  68. foo ()
  69. {
  70.   fprintf (stderr, "goodbye world\n");
  71. }
  72. ----------------------------------------
  73.  
  74.     I'm compiling them both with /bin/cc and using the -ldl option
  75. to /bin/ld.  Does anyone know what I am doing wrong and what
  76. the cryptic error message:
  77.  
  78. ld.so: mmap data error (22) for /i0/da/ud/schmidt/tmp/x1.o
  79.  
  80. means?!
  81.  
  82.     Thanks,
  83.  
  84.         Doug
  85. --
  86. His life was gentle, and the elements so            | Douglas C. Schmidt
  87. Mixed in him that nature might stand up             | schmidt@ics.uci.edu
  88. And say to all the world: "This was a man."         | ucivax!schmidt
  89.    -- In loving memory of Terry Williams (1971-1991)| (714) 856-4101
  90.