public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: Visual Studio linking
@ 2004-12-12 22:38 Daniel Starin
  2004-12-12 22:55 ` Larry Hall
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel Starin @ 2004-12-12 22:38 UTC (permalink / raw)
  To: cygwin; +Cc: alastair.growcott

Hi.

	I am also trying to use functions implemented in cygwin1.dll with
Visual Studio as discussed below.  After started a blank console application
and following steps below, I get to linking which gives me the following
error:

Linking...
LIBCMTD.lib(crt0.obj) : error LNK2005: _mainCRTStartup already defined in
crt0.obj

Any suggestions?

Thanks,

Dan

---------------------------------------------------------------
From http://www.cygwin.com/ml/cygwin/2004-06/msg00274.html
And Faq...

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/

^ permalink raw reply	[flat|nested] 10+ messages in thread
* Visual Studio linking
@ 2004-06-02  8:20 Alastair Growcott
  2004-06-02  8:52 ` Max Bowsher
  0 siblings, 1 reply; 10+ messages in thread
From: Alastair Growcott @ 2004-06-02  8:20 UTC (permalink / raw)
  To: cygwin

Hi.

I have read all the FAQs and stuff. I have searched the web. I would like a step by step list of instructions to achieve the following.

I want to use check to test an MFC application. This means I must use the Visual Studio compiler, cl, and linker, link.
Check calls fork(). This function is implemented in the cygwin1.dll.
I cannot link using the DLL. I read somewhere that libcygwin.a is equivalent to the cygwin1.lib, but when I try and link against it I get all sorts of bizarre symbols not found. According to cygcheck, cygwin1.dll only has dependencies on standard Windows DLLs that I am already linking against.

So how do I;

a) obtain a version of cygwin1.lib that I can link against using the Visual Studio linker that will work nicely and neatly, or
b) link against libcygwin.a using the Visual Studio linker.

 
Alastair Growcott
Software Maintenance Engineer

BakBone Software
Merck House
Seldown Lane
Poole, BH15 1TW
P +44 (0)1202 241000
F +44 (0)1202 249000
alastair.growcott@bakbone.com
www.bakbone.com
> 


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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2004-12-17 22:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-12 22:38 Visual Studio linking Daniel Starin
2004-12-12 22:55 ` Larry Hall
2004-12-17 21:35   ` Daniel Starin
2004-12-17 22:20     ` Larry Hall
  -- strict thread matches above, loose matches on Subject: below --
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-07 14:40         ` Re[5]: " Alastair Growcott
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

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