delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/08/27/16:47:18

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Fri, 27 Aug 2004 16:47:04 -0400 (EDT)
From: Igor Pechtchanski <pechtcha AT cs DOT nyu DOT edu>
Reply-To: cygwin AT cygwin DOT com
To: Oliver <oliver DOT schoenborn AT utoronto DOT ca>
cc: cygwin AT cygwin DOT com
Subject: Re: questions about DLL's: .a, .def, and .dll
In-Reply-To: <loom.20040827T221407-94@post.gmane.org>
Message-ID: <Pine.GSO.4.61.0408271642080.9041@slinky.cs.nyu.edu>
References: <loom DOT 20040827T173827-426 AT post DOT gmane DOT org> <Pine DOT GSO DOT 4 DOT 61 DOT 0408271423560 DOT 6181 AT slinky DOT cs DOT nyu DOT edu> <loom DOT 20040827T221407-94 AT post DOT gmane DOT org>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.39

On Fri, 27 Aug 2004, Oliver wrote:

> Igor Pechtchanski <pechtcha <at> cs.nyu.edu> writes:
>
> > The newer versions of gcc apparently allow you to link directly to a .dll
> > file.  The .def and .a are needed for older versions of gcc, and possibly
> > for some other tools.
> >
> > [...]
> >
> > The reason you want an 'extern "C"' for DLL functions in general is that
> > g++ and the Windows C++ compilers (notably VC++) use different name
> > munging schemes, so a DLL built with C++ symbols won't be usable from
> > other applications that try to call those functions.  The reason you want
> > it for DllMain is that the Windows loader will be looking for the unmunged
> > name "DllMain".  Are you sure that it's really invoked when the DLL is
> > loaded?
>
> Actually I found something quite interesting on a "Tcl extensions in
> Windows" wiki website, where a poster says that DllMain, __decl...
> import export, windows.h etc are no longer needed with g++. Sure enough,
> the following example works:
>
> 1) create a dll.h file that contains a class definition, just like you
> would on Unix (i.e. no __decl... macros, no extern etc)
> 2) create a dll.cc file that contains some of your class definition methods
> 3) then create the dll with
>
>    g++ -c dll.o
>    g++ -shared dll.o -otestdll.dll
>
> 4) create a testMain.cc file with a main() that #includes dll.h and uses
> some things defined in dll.cc
> 5) build with
>
>    g++ -o testMain testMain.cc -L. -ltestdll
>
> 6) run testMain.exe to make sure it works
>
> Note that extern, gcc, import/export macros and declarations, DllMain
> etc were NOT needed. Gcc seems to export everything, like it would on
> *nix (except, presumably, functions declared static and things in
> anonymous namespace -- exercise left to the reader ;).
>
> You can tell the linker to generate a .def file by adding "-Wl,--output-
> def=testdll.def" when creating the testdll.dll. This shows all symbols
> exported. Running nm on testdll.dll also shows
>
> 67488220 T _DllMain AT 12
> 67481000 T _DllMainCRTStartup AT 12
>
> which means that gcc auto-generated it, and did not mangle for C++ use.
>
> Does anyone know if testdll.dll, created this way, would be linkable from a
> VC++ program? I don't have access to VC++.

First off, yes, a DllMain will be generated automatically if you don't
provide it.  That still doesn't address the issue of whether you should
declare it as 'extern "C"' when you *do* provide it.  It seems that
APIENTRY is enough.

Secondly, the resultant DLL will be linkable from a VC++ program, but the
C++ functions in it will not be accessible from code compiled with VC++.
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha AT cs DOT nyu DOT edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor AT watson DOT ibm DOT com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"Happiness lies in being privileged to work hard for long hours in doing
whatever you think is worth doing."  -- Dr. Jubal Harshaw

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

- Raw text -


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