delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/06/07/10:40: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: Mon, 7 Jun 2004 15:38:21 +0100 (GMT Daylight Time)
From: Alastair Growcott <Alastair DOT Growcott AT bakbone DOT co DOT uk>
Subject: Re[5]: Visual Studio linking
To: cygwin AT cygwin DOT com
Message-ID: <Mahogany-0.66.0-604-20040607-153821.00@bakbone.co.uk>
MIME-Version: 1.0
References: <Mahogany-0 DOT 66 DOT 0-796-20040602-091909 DOT 00 AT bakbone DOT co DOT uk> <001801c4487e$dca77e20$78d96f83 AT robinson DOT cam DOT ac DOT uk> <Mahogany-0 DOT 66 DOT 0-796-20040602-101718 DOT 00 AT bakbone DOT co DOT uk> <Mahogany-0 DOT 66 DOT 0-796-20040602-131524 DOT 00 AT bakbone DOT co DOT uk> <Mahogany-0 DOT 66 DOT 0-796-20040602-144338 DOT 00 AT bakbone DOT co DOT uk>
In-Reply-To: <Mahogany-0.66.0-796-20040602-144338.00@bakbone.co.uk>
Organization: BakBone Software
X-IsSubscribed: yes

To all those who said it couldn't be done...I've done it :)

Hahahaha.

Seriously, it is quite easy once you figure it out, and I am sure there are plenty of people who helped write Cygwin who probably knew but couldn't be bothered to tell me.

It involves a couple of minor hacks. It would be nice if cygwin1.dll could export the cygwin_crt0() function.

Here is how you do it:

1) Use the impdef program to generate a .def file for the cygwin1.dll
    impdef cygwin1.dll > cygwin1.def

2) Use the MS VS linker (lib) to generate an import library
    lib /def=cygwin1.def /out=cygwin1.lib

3) Create a file "my_crt0.c" with the following contents
  
#include <sys/cygwin.h>
#include <stdlib.h>

typedef int (*MainFunc) (int argc, char *argv[], char **env);

void
my_crt0 (MainFunc f)
{
  cygwin_crt0(f);
}

4) Use gcc in a Cygwin prompt to build my_crt0.c into a DLL (e.g. my_crt0.dll). Follow steps 1 and 2 to generate .def and .lib files for the DLL.

5) Download crt0.c from the cygwin website and include it in your sources. Modify it to call my_crt0() instead of cygwin_crt0().

6) Build your object files using the MS VC compiler cl.

7) Link your object files, cygwin1.lib, and my_crt0.lib (or whatever you called it) into the executable.

Note that if you are using any other Cygwin based libraries that you will probably need to build them as DLLs using gcc and then generate import libraries for the MS VC linker.

Alastair.





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