VC与Cygwin的结合

http://www.cnblogs.com/androidme/archive/2013/03/16/2963262.html

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


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值