zsh-workers
 help / color / mirror / code / Atom feed
* Getting dynamic loading to work on cygwin
@ 2000-06-02 11:03 Peter Stephenson
  2000-06-02 13:43 ` Peter Stephenson
  2000-06-02 14:11 ` Use and abuse of dynamic loading " Andrej Borsenkow
  0 siblings, 2 replies; 12+ messages in thread
From: Peter Stephenson @ 2000-06-02 11:03 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 1139 bytes --]

In case anyone has a chance to play around with it, here's a minimal
example of getting dynamically loaded libraries to work on cygwin.  The
changes to what we have already should be fairly mechanical but will still
require a bit of work.  Zefram's and Oliver's work on export files will
come in handy, since it looks like cygwin will need a very similar set to
AIX (there are tools to generate them automatically, but we have enough
in place already to get it right).  Just unpacking these and running make
should create a main.exe and a dl.dll; running the first loads the second.
I actually found out about the dllwrap incantation (which does all the hard
work for you) from the perl dynamic loading configuration.

There may be some issues about search paths still to resolve, since there
are both .a (list of exports) and a .dll (the actual library) files; I
haven't tried moving the files into different directories.  It might also
be more efficient to use dlltool directly rather than rely on dllwrap, but
I for one don't have the patience.

In case anyone is any doubt, this will *not* be in the release which is
immediately due.


[-- Attachment #2: Makefile --]
[-- Type: text/plain, Size: 392 bytes --]

.SUFFIXES: .so .dll

CC = gcc
CFLAGS = -O -g -Wall
LIBS = # -ldl

all: main dl.dll

main: main.o
	$(CC) -o main main.o $(LIBS)

dl.o: dl.c
	gcc $(CFLAGS) -c dl.c

dl.dll : dl.o
	dllwrap --dllname $*.dll --driver-name gcc --dlltool dlltool --as as --def $*.def --output-lib lib$*.a dl.o

dl.so : dl.o
	gcc -G -o dl.so dl.o

clean:
	rm -f dl.o dl.so dl.dll main.o main libdl.a main.exe dl.base

[-- Attachment #3: main.c --]
[-- Type: text/plain, Size: 453 bytes --]

#include <stdio.h>
#include <dlfcn.h>

int main(int argc, char **argv)
{
    void *handle, *symbol;
    int ret;

    handle = dlopen("./dl.dll", RTLD_LAZY);
    if (handle == NULL) {
	fprintf(stderr, "dlopen failed.\n");
	return 1;
    }
    symbol = dlsym(handle, "module");
    if (symbol == NULL) {
	fprintf(stderr, "dlsym failed.\n");
	return 1;
    }
    ret = ((int (*)(void))symbol)();

    printf("module returned %d\n", ret);

    return 0;
}

[-- Attachment #4: dl.c --]
[-- Type: text/plain, Size: 94 bytes --]

#include <stdio.h>

int module(void)
{
    printf("This is the module.\n");
    return 42;
}


[-- Attachment #5: dl.def --]
[-- Type: text/plain, Size: 16 bytes --]

EXPORTS
	module

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2000-07-06 11:08 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-02 11:03 Getting dynamic loading to work on cygwin Peter Stephenson
2000-06-02 13:43 ` Peter Stephenson
2000-06-02 14:19   ` Andrej Borsenkow
2000-06-02 15:00     ` Peter Stephenson
2000-06-02 15:16       ` maurice s. barnum
2000-06-02 16:17         ` Peter Stephenson
2000-07-06 10:15         ` Andrej Borsenkow
2000-07-06 11:07           ` Peter Stephenson
2000-06-02 14:11 ` Use and abuse of dynamic loading " Andrej Borsenkow
2000-06-02 14:24   ` Peter Stephenson
2000-06-02 14:52     ` Use and abuse of dynamic loading RE: Getting dynamic loading towork " Andrej Borsenkow
2000-06-06 21:52       ` Fletch

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).