1:生成cygwin1.lib
impdef cygwin1.def cygwin1.dll
lib /DEF:cygwin1.def /OUT:cygwin1.lib
2:生成my-crt0.lib
gcc -shared my-crt0.c -o my-crt0.dll
impdef my-crt0.def my-crt0.dll
lib /DEF:my-crt0.def /OUT:my-crt0.lib
3: 把crt0.c包含中工程中
my_crt0.c
#include <sys/cygwin.h> #include <stdlib.h> typedef int (*MainFunc) (int argc, char *argv[], char **env); void my_crt0 (MainFunc f) { cygwin_crt0(f); }
crt0.c
/* crt0.c. Copyright 2001, 2005 Red Hat, Inc. This software is a copyrighted work licensed under the terms of the Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ /* In the following ifdef'd i386 code, the FPU precision is set to 80 bits and all FPU exceptions are masked. The former is needed to make long doubles work correctly. The latter causes the FPU to generate NaNs and Infinities instead of signals for certain operations. */ #ifdef __i386__ #define FPU_RESERVED 0xF0C0 #define FPU_DEFAULT 0x033f /* For debugging on *#!$@ windbg. bp for breakpoint. */ int __cygwin_crt0_bp = 0; #endif typedef int (*MainFunc) (int argc, char *argv[], char **env); void my_crt0 (MainFunc f); //extern int main (int argc, char **argv); extern int main (int argc, char **argv, char **env); //void cygwin_crt0 (int (*main) (int, char **)); void mainCRTStartup () { #ifdef __i386__ (void)__builtin_return_address(1); asm volatile ("andl $-16,%%esp" ::: "%esp"); if (__cygwin_crt0_bp) asm volatile ("int3"); { volatile unsigned short cw; /* Get Control Word */ __asm__ volatile ("fnstcw %0" : "=m" (cw) : ); /* mask in */ cw &= FPU_RESERVED; cw |= FPU_DEFAULT; /* set cw */ __asm__ volatile ("fldcw %0" :: "m" (cw)); } #endif my_crt0 (main); } //void WinMainCRTStartup(void) __attribute__ ((alias("mainCRTStartup")));
参考
http://blog.csdn.net/songbohr/article/details/5276128
http://blog.csdn.net/cs_21cn/article/details/7419744
http://cygwin.com/faq/faq.programming.html#faq.programming.msvs-mingw
http://cygwin.com/ml/cygwin/2004-06/msg00274.html
impdef下载
http://mirrors.zoreil.com/webclub.kcom.ne.jp/ma/colinp/gcc.html