home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!know!mips2!news.bbn.com!noc.near.net!news.Brown.EDU!qt.cs.utexas.edu!cs.utexas.edu!uwm.edu!rpi!usc!news.service.uci.edu!ucivax!schmidt
- From: schmidt@liege.ics.uci.edu (Douglas C. Schmidt)
- Newsgroups: comp.unix.questions
- Subject: Dynamic linking on Sun OS 4.1
- Message-ID: <2B08475F.4802@ics.uci.edu>
- Date: 17 Nov 92 01:14:07 GMT
- Reply-To: schmidt@ics.uci.edu (Douglas C. Schmidt)
- Distribution: inet
- Organization: University of California at Irvine: ICS Dept.
- Lines: 77
- Nntp-Posting-Host: liege.ics.uci.edu
-
- 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
-