delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/03/08/18:14:02

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
MIME-Version: 1.0
Message-ID: <15497.17766.680903.327350@mango.psc.edu>
Date: Fri, 8 Mar 2002 18:12:38 -0500
From: Greg Hood <ghood AT psc DOT edu>
To: cygwin AT cygwin DOT com
Subject: dlopen error with nested dll's
X-Mailer: VM 7.00 under Emacs 20.7.1

I'm trying to dlopen a .dll which depends on another .dll, and
am getting a "Win32 error 127".  I'm not totally sure I am building
the dll's correctly, so that might be one source of the problem.
This is with Cygwin version 1.3.10, gcc version 2.95.3-5,
dlltool version 2.11.92, and Windows NT 4.0.

Here is an example.  There are 3 source files: m.c, a.c, and b.c.
a.c is used to build a.dll, which m.exe can dlopen without problems.
However, b.c is used to build b.dll, but this depends on symbols in
a.dll.  m.exe gets an error upon trying to dlopen b.dll.

------------------------m.c--------------------------------------------
#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>

main ()
{
  void *a_handle, *b_handle;
  void (*a)(), (*b)();

  if ((a_handle = dlopen("a.dll", RTLD_NOW)) == NULL)
    {
      printf("dlopen of a.dll failed: %s\n", dlerror());
      exit(1);
    }
  if ((a = (void (*)()) dlsym(a_handle, "a")) == NULL)
    {
      printf("dlsym of a failed: %s\n", dlerror());
      exit(1);
    }
  (*a)();

  if ((b_handle = dlopen("b.dll", RTLD_NOW)) == NULL)
    {
      printf("dlopen of b.dll failed: %s\n", dlerror());
      exit(1);
    }
  if ((b = (void (*)()) dlsym(b_handle, "b")) == NULL)
    {
      printf("dlsym of b failed: %s\n", dlerror());
      exit(1);
    }
  (*b)();
}

------------------------end of m.c-------------------------------------
------------------------a.c--------------------------------------------
#include <stdio.h>

void a()
{
  printf("a called.\n");
}
------------------------end of a.c-------------------------------------
------------------------b.c--------------------------------------------
#include "stdio.h"
extern void a();

void b()
{
  printf("b called.\n");
  a();
}
------------------------end of b.c-------------------------------------

I compile and run these with the following commands:
gcc -g -c -o m.o m.c
gcc -g -c -o a.o a.c
gcc -shared -o a.dll a.o
gcc -g -c -o b.o b.c
echo EXPORTS > a.def
nm a.dll | grep ' T _' | sed 's/.* T _//' >> a.def
dlltool --def a.def --dllname a.dll --output-lib a.a
gcc -shared -o b.dll b.o a.a
gcc -g -o m.exe m.o

./m.exe
a called.
dlopen of b.dll failed: dlopen: Win32 error 127

Any idea what is going wrong, or what else to try?
Thanks.
--Greg Hood
  Pittsburgh Supercomputing Center

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019