Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
From: svoboda@cs.cmu.edu
Reply-To: svoboda@cs.cmu.edu
To: cygwin@sourceware.org
Subject: Building DLL's using g++, not gcc
Date: Mon, 17 Jan 2005 17:46:25 -0500
User-Agent: KMail/1.7.2
Cc: David Svoboda <svoboda@cs.cmu.edu>
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200501171746.26708.svoboda@cs.cmu.edu>
Source-Info:  Sender is really svoboda+@mandal.lti.cs.cmu.edu

I've been trying to build a DLL using g++, and given the problems I was 
having, I decided to try a 'toy' example, which is available at:
	http://cygwin.com/cygwin-ug-net/dll.html
I tweaked the two files around thusly:


hello.C:
-----
#include <stdio.h>
int hello() { printf("Hello World\n");}
-----

main.C:
-----
#include <stdio.h>
typedef void (*fn_type)();

extern "C" {
  int dlopen(char*);
  int dlsym( int, char*);
}

int main() {
  int handle = 0;
  fn_type fn = 0;
  if ((handle = dlopen( "hello.dll")) == 0) {
    printf( "Cannot open hello.dll\n");
  }
  if ((fn = (fn_type) dlsym( handle, "hello")) == 0) {
    printf( "Cannot open hello()\n");
  }
  fn();
}
-----

This way, hello.C is a valid C or C++ application, and main.C is a
valid C++ application. I build main.exe by:

	g++ -o main main.C

If I build hello.dll this way, it works:

	gcc -shared -o hello.dll hello.C
	./main
	Hello world!

But if I build hello.dll this way, it doesn't work:

	g++ -shared -o hello.dll hello.C
	./main
	bash: [2084: 2] testaddr: Inappropriate ioctl for device

Why? What am I doing wrong?

~David Svoboda


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

