delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/03/10/06:45:15

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
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
To: cygwin AT cygwin DOT com
From: Alejandro Lopez-Valencia <dradul AT etb DOT net DOT co>
Subject: Re: Creating DLL's for use with MSVC
Date: Wed, 10 Mar 2004 06:44:01 -0500
Organization: Casa de Cuckoo
Lines: 62
Message-ID: <c2mv33$u1m$1@sea.gmane.org>
References: <D9B6A11B-7268-11D8-B092-000393C92B12 AT foi DOT se>
Mime-Version: 1.0
X-Complaints-To: usenet AT sea DOT gmane DOT org
Keywords: No keywords can be a good thing.
X-Gmane-NNTP-Posting-Host: 200.119.72.113
X-Archive: encrypt
Mail-Copies-To: never
X-Newsreader: Do you care?
X-UserAgent: Does it really matter?
X-Newsreader: Forte Agent 2.0/32.646
Reply-To: cygwin AT cygwin DOT com

On Wed, 10 Mar 2004 08:59:26 +0100, Niklas Wallin wrote in
<D9B6A11B-7268-11D8-B092-000393C92B12 AT foi DOT se>:

>We are currently porting a linux C++ project to windows. The project 
>consists of several dll's (or .so's). To recreate those dll's in 
>Windows it seems like you have to add a lot of __cdecls definitions or 
>use a definitions file. Neither method is appealing to us. So, I read 
>somewhere that Cygwin might do the trick by exporting all symbols. So, 
>I started to compile dll's in cygwin:
>
>c++ -shared -mno-cygwin -o mydll.dll mydll.cpp \
>	-Wl, --out-implib=mydll.lib
>	-W1,--output-def=mydll.def
>	-W1,--export-all-symbols
>

Try:

cc++ -shared -mno-cygwin -o mydll.dll mydll.cpp \
	-Wl,--out-implib=mydll.lib \
	-W1,--output-def=mydll.def \
	-W1,--export-all-symbols \
	-Wl,--enable-auto-import \
	-Wl,--enable-auto-image-base \
	-Wl,--compat-implib \
	-Wl,--add-stdcall-alias \
	-Wl,--enable-stdcall-fixup

Yu should recycle recycle your def file. You see, it will contain a
lot of unnecessary symbols, so... After you have obtained a def file
above, edit it to include only the symbols you really need exported
and include it in your project for future use. Then you can do:

cc++ -shared -mno-cygwin -o mydll.dll mydll.cpp mydll.def \
	-Wl,--out-implib=mydll.lib \
	-Wl,--compat-implib \
	-Wl,--enable-auto-import \
	-Wl,--enable-auto-image-base \
	-Wl,--add-stdcall-alias \
	-Wl,--enable-stdcall-fixup

To obtain a well behaved dll and a (probably?) usable import library.

If you are using this within a Makefile, you should rather input the
object files. Like this:

cc++ -shared -mno-cygwin $(CXXFLAGS) -o mydll.dll \
	-Wl,--out-implib=mydll.lib \
	-Wl,--compat-implib \
	-Wl,--add-stdcall-alias \
	-Wl,--enable-stdcall-fixup \
	-Wl,--enable-auto-import \
	-Wl,--enable-auto-image-base \
	-Wl,--whole-archive \
		$(MY_DLL_OBJECT_FILES_LIST) \
		my_dll_symbols_export_list.def \
	-Wl,--no-whole-archive \
		$(ANY_LIBRARIES_THE_DLL_SHOULD_AUTO_LOAD) 

See GNU GCC and GNU binutils' documentation for an explanation. (This,
btw, should go in the FAQ, consider it a contribution).



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