Cygwin in Visual Studio

原文:http://stackoverflow.com/questions/1926311/cygwin-in-visual-studio

Ask:

I'm trying to port an old program I wrote for class from KDev in Ubuntu to Windows Visual Studio 2008 using Cygwin as a personal learning exercise. I have the include path configured to include C:\cygwin\usr\include but it doesn't read the .h files properly.

Namely I'm curious as to how one would go about using unix sockets.h functionality in a Visual Studio environment using Cygwin. Has anybody ever got this working or have an easier way to go about doing this?

Answer:


There are several ways to go about this that could be made to work, depending upon your exact goals. The simplest way is probably just to create a Visual Studio "makefile" project that fires off a custom build command to run a makefile you've built. But that keeps you away from a lot of the nice benefits of Visual Studio as an IDE, so I'm guessing that's not really what you're after.

If you want a more fully integrated solution, you're going to need to do two things. First of all, you're going to need to change out all of your include/library paths to avoid the Microsoft ones and go after the Cygwin ones instead. You can do this by selecting "Tools->Options" from the menu, then choosing "Projects and Solutions->VC++ Directories" from the tree on the left hand side of the window that comes up. You'll have options to change the search directories for executables, headers, libraries, etc. For what you're trying to do, I'd suggest removing everything and adding in just the cygwin directories.

Second, you'll have to tell Visual Studio to use the gcc/g++ compiler. This is a bit trickier. VS supports custom build rules for custom file types... but it seems to have C++ hardwired in for the Microsoft compiler. I don't really know a great way around that except to use your own custom file extension. You can try the standard unix extensions of .c (C files) and .cc (C++ files), but I suspect Visual Studio will automatically pick up on those. You may have to go with something totally foreign.

If you right click on your project in the Solution Explorer and select "Custom Build Rules" you'll be given an interface that will let you create your custom build rules for the file extension you've chosen. The interface is relatively straightforward from there.

This might not get you exactly what you wanted, but it's probably about as close as you're going to get with Visual Studio.

转载于:https://www.cnblogs.com/black/p/5171769.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CMake、Cygwin、MinGW、Visual Studio 都可以用于编译 C/C++ 源码,它们各有优缺点,适用于不同的开发环境和项目需求。 1. CMake CMake 是一个跨平台的编译工具,可以自动生成 Makefile、Visual Studio 项目等,用于编译 C/C++ 代码。CMake 的优点是可以自动生成跨平台的编译文件,提高了代码的可移植性。缺点是需要学习 CMake 的语法和配置方式。 2. Cygwin Cygwin 是 Windows 上的一个开发环境,它提供了一组 Unix 工具和库,可以用来编译 Unix/Linux 下的程序。Cygwin 的优点是提供了完整的 Unix 开发环境,可以很方便地移植 Unix/Linux 下的程序到 Windows 平台。缺点是需要安装 Cygwin 环境和 Unix 库,占用较大的硬盘空间。 3. MinGW MinGW 是 Windows 上的一个开发环境,它提供了一组 GNU 工具,包括 GCC 编译器、make 工具等,可以用来编译 C/C++ 源码。MinGW 的优点是提供了常用的 GNU 工具,可以很方便地进行开发和编译。缺点是不支持完整的 Unix 开发环境,无法移植所有的 Unix/Linux 下的程序。 4. Visual Studio Visual Studio 是 Windows 上常用的开发工具之一,可以用它来编译 C/C++ 源码。Visual Studio 的优点是提供了完整的 Windows 开发环境,可以很方便地进行开发和编译。缺点是不支持跨平台的编译,无法移植到其他平台。 综上所述,选择哪种编译方式,需要根据具体的开发环境和项目需求进行选择。如果需要编写跨平台的程序,可以考虑使用 CMake;如果需要移植 Unix/Linux 下的程序到 Windows 平台,可以考虑使用 Cygwin;如果只需要在 Windows 平台上进行开发和编译,可以考虑使用 MinGW 或 Visual Studio

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值