public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Alastair Growcott <Alastair.Growcott@bakbone.co.uk>
To: cygwin@cygwin.com
Subject: Re[5]: Visual Studio linking
Date: Mon, 07 Jun 2004 14:40:00 -0000	[thread overview]
Message-ID: <Mahogany-0.66.0-604-20040607-153821.00@bakbone.co.uk> (raw)
In-Reply-To: <Mahogany-0.66.0-796-20040602-144338.00@bakbone.co.uk>

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/

  parent reply	other threads:[~2004-06-07 14:40 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-02  8:20 Alastair Growcott
2004-06-02  8:52 ` Max Bowsher
2004-06-02  9:18   ` Re[2]: " Alastair Growcott
2004-06-02 12:16     ` Re[3]: " Alastair Growcott
2004-06-02 13:45       ` Re[4]: " Alastair Growcott
2004-06-02 13:55         ` Dave Korn
2004-06-07 14:40         ` Alastair Growcott [this message]
2004-06-07 14:56           ` Christopher Faylor
2004-06-07 16:15             ` Re[2]: " Alastair Growcott
2004-06-07 16:25               ` Christopher Faylor
2004-06-08  9:04                 ` Alastair Growcott
2004-06-08 13:02                   ` Christopher Faylor
2004-06-07 20:42           ` Re[5]: " Joshua Daniel Franklin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Mahogany-0.66.0-604-20040607-153821.00@bakbone.co.uk \
    --to=alastair.growcott@bakbone.co.uk \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).