zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@cambridgesiliconradio.com>
To: zsh-workers@sunsite.auc.dk (Zsh hackers list)
Subject: Getting dynamic loading to work on cygwin
Date: Fri, 02 Jun 2000 12:03:05 +0100	[thread overview]
Message-ID: <0FVI00DP2XD5AS@la-la.cambridgesiliconradio.com> (raw)

[-- 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

             reply	other threads:[~2000-06-02 11:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-06-02 11:03 Peter Stephenson [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0FVI00DP2XD5AS@la-la.cambridgesiliconradio.com \
    --to=pws@cambridgesiliconradio.com \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).