cygwin跨平台移植 gcc+vc联合使用的方法和注意事项

    前段时间做一个把linux代码移植到vc上的工程,选择cygwin环境,直接交叉编译通过。后来为了调试方便需要把源代码全部放到vc下编译,在网上搜索相关资料,发现在cygwin官方的FAQ中给出了具体的方法。下面我就里面的关键步骤做一个简单的解释:首先是官方的原文:

 

How do I use cygwin1.dll with Visual Studio or MinGW?
 
  If you want to load the DLL dynamically, read winsup/cygwin/how-cygtls-works.txt and the sample code in winsup/testsuite/cygload to understand how this works. The short version is:

Make sure you have 4K of scratch space at the bottom of your stack.

Invoke cygwin_dll_init():

HMODULE h = LoadLibrary("cygwin1.dll");
void (*init)() = GetProcAddress(h, "cygwin_dll_init");
init();
If you want to link statically from Visual Studio, to my knowledge none of the Cygwin developers have done this, but we have this report from the mailing list that it can be done this way:

Use the impdef program to generate a .def file for the cygwin1.dll (if you build the cygwin dll from source, you will already have a def file)

impdef cygwin1.dll > cygwin1.def
Use the MS VS linker (lib) to generate an import library

lib /def=cygwin1.def /out=cygwin1.lib
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);
  }
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.

Download crt0.c from the cygwin website and inc

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值