home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.unix.programmer:5316 comp.sys.sun.misc:5303 comp.unix.solaris:324
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!sdd.hp.com!elroy.jpl.nasa.gov!usc!news.service.uci.edu!ucivax!schmidt
- From: schmidt@net1.ics.uci.edu (Douglas C. Schmidt)
- Subject: Dynamic linking on Sun OS
- Nntp-Posting-Host: net1.ics.uci.edu
- Message-ID: <2B0947EA.4501@ics.uci.edu>
- Newsgroups: comp.unix.programmer,comp.sys.sun.misc,comp.unix.solaris
- Reply-To: schmidt@ics.uci.edu (Douglas C. Schmidt)
- Organization: University of California at Irvine: ICS Dept.
- Lines: 77
- Date: 17 Nov 92 19:28:43 GMT
-
- Hi,
-
- I've been experiementing with dynamic linking via Sun OS 4.1.2.
- However, I'm having the following problem when I try to use the
- dlopen(), dlsym() library:
-
- % ./a.out ~/tmp/x1.o _foo
- ld.so: mmap data error (22) for /i0/da/ud/schmidt/tmp/x1.o
-
- The main program looks like this:
-
- ----------------------------------------
- #include <stdio.h>
- #include <dlfcn.h>
-
- int
- main (argc, argv)
- int argc;
- char *argv[];
- {
- char *path = argv[1];
- char *symbol = argv[2];
- void *handle;
- int (*f)(void);
-
- if ((handle = dlopen (path, 1)) == 0)
- dlerror ("dlopen failed");
-
- fprintf (stderr, "handle = %d\n", handle);
-
- if ((f = (int (*)(void)) dlsym (handle, symbol)) == (int (*)(void)) 0)
- dlerror ("dlsym failed");
-
- fprintf (stderr, "f = %d\n", f);
-
- if (f != 0)
- (*f)();
- else
- fprintf (stderr, "symbol %s not found\n", symbol);
- dlclose (handle);
- }
- ----------------------------------------
-
- The x1.c file looks like this:
-
- ----------------------------------------
- #include <stdio.h>
-
- void
- init ()
- {
- fprintf (stderr, "starting x1\n");
- }
-
- int
- foo ()
- {
- fprintf (stderr, "goodbye world\n");
- }
- ----------------------------------------
-
- I'm compiling them both with /bin/cc and using the -ldl option
- to /bin/ld. Does anyone know what I am doing wrong and what
- the cryptic error message:
-
- ld.so: mmap data error (22) for /i0/da/ud/schmidt/tmp/x1.o
-
- means?!
-
- Thanks,
-
- Doug
- --
- His life was gentle, and the elements so | Douglas C. Schmidt
- Mixed in him that nature might stand up | schmidt@ics.uci.edu
- And say to all the world: "This was a man." | ucivax!schmidt
- -- In loving memory of Terry Williams (1971-1991)| (714) 856-4101
-