views:

558

answers:

3

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?

+3  A: 

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.

Russell Newquist
The custom extensions and build rules worked after a little tweaking, I haven't worked with custom build rules before so I didn't even think of that. It's not a perfect solution and it's by no means an efficient way to go about doing things, but this was intended more as a learning experience to test limits and discover new things than anything practical.
WarrenB
+1  A: 

Simply speaking, don't do that. It would be just waste of time. I tried it several times, but always failed. Mostly, I was frustrated by many linking errors, and also was unable to use VS as a debugger.

You can use Visual Studio for editing and browsing source code. It is nice because VS provides the best C/C++ intellisense features (e.g., Auto completion, fast go to definition/declaration). But, it is very hard to use cygwin tool chains with Visual Studio 2008. Visual Studio 2008 is not designed to work with other tool chains. Specifically, you need to change (1) headers, (2) libraries, (3) compiler and (4) linker. However, it is generally very hard, or you need to trade off with the nice features of Visual Studio.

The strongest feature of Visual Studio is its debugging ability such as fully integrated debugging environment and very easy watch windows (e.g., you can see STL vector's element directly in watch windows). However, you can't do this if you would change fundamental tool chain (although I am very suspicious it is even possible to safely build with Visual Studio and cygwin tool chains).

Unfortunately, current Visual Studio 2008 is not for cygwin/MinGW.

minjang
A: 

Use Visual Studio with the Windows OS. Create a new project that uses the same sources as the Ubuntu version. Build. You will get compilation errors.

Change the source files that use Ubuntu specific header to use either Windows headers or another framework (I suggest to avoid MFC at all costs, but that is my opinion).

For GUI stuff, you may have to switch to something that can cross over between Linux and Windows, such as wxWidgets and QT.

Visual Studio has utilities that will convert a makefile into a project file.

These are the steps that I performed when I converted from Cygwin to Visual Studio.

Thomas Matthews