Cygwin in Visual Studio - c++

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?

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.

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.

This is an old question, but since it comes up first (for SO) on a Google search I wanted to share that it looks like the latest Visual Studio versions do support this.
For instructions, refer to this blog post:
https://blogs.msdn.microsoft.com/vcblog/2017/07/19/using-mingw-and-cygwin-with-visual-cpp-and-open-folder/

Related

Creating a portable, cross-platform, open-source C++ GUI application that works out of the box?

I've been looking around to see how I'd accomplish that which is described in the title. That is, I'd like to create a C++ GUI application that:
is portable (no installer)
is cross-platform (Qt solves this)
is open source
works out of the box (i.e. no C++ redistributable installs needed)
I've run into several issues trying to accomplish this. I've narrowed it down to using Qt and NOT using the Visual Studio compiler. Let me explain.
Using Qt would fulfill the cross-platform requirement; it's also highly acclaimed in regard to C++ GUI applications. The issue lies with portability and not having a ton of dependency packages to install before being able to use the application. My goal would be for someone to download a .zip file containing an .exe (and I'd be willing to include other support files e.g. DLLs if necessary) and be able to extract and run that exe out of the box without having to do anything else.
And here's another kicker: as much as I'd like to use Visual Studio (with the Qt Visual Studio Add-in), it just doesn't seem feasible given my requirements. This post covers my issues pretty nicely. Simply put, if I use the Visual Studio compiler, I'd need to either create an installer (no longer a portable app), redistribute some Microsoft DLLs with the app (possible licensing and redist issues here?), or statically link the Visual C++ libraries into the executable (frowned upon technique).
Is there any way to be able to use Visual Studio and fulfill the requirements listed above? Visual Studio is just too fully-featured to pass up. If it's not possible, I think the only other alternatives would be to use a different IDE and/or compiler. For example, I could use QtCreator with MinGW, but then I'd be losing out on some awesome VS debugging features.
My main questions:
Is there any way I can fulfill the requirements above and still use Visual Studio?
Am I wrong about QtCreator not being as fully functional as Visual Studio?
What would be the best way to approach fulfilling my application requirements?
Thanks in advance.
I think your best bet would be to use QT with the MinGW environment. It allows you to create a portable application that supplies runtime DLLs by itself, with added bonus of being completely open source. The QT online installer gives you the option to install the complete MinGW system, and it will work out of the box, not much setup needed.
You could still use Visual Studio for development; there even is a QT plugin for it (I am not sure if VS2015 is supported, but if not that should only take some time).
QTCreator is actually a quite nice IDE, but it cannot stand up to Visual Studio. It is obviously optimized to cater to the needs of QT programmers, but I found that it is quite clunky from time to time. If your project is small it could be a viable choice, but since Visual Studio 2015 Community is basically free I would opt for that. The VS plugin will still use QTCreator's GUI editor though (which is really good)

Can I force visual studio to use mingw compiler

I don't like qt creator as IDE and love VS, but I must use exactly mingw compiler. Sad story :'(
Just set up a makefile project - that way you can tell VC what command to run to compile your files.
You have to maintain a makefile in addition to the Visual Studio project, but that's really not too big of a problem since in that case the VS project becomes just a list of the files you want Visual Studio to know about.
Unfortunately, the VS debugger is not useful in this scenario, but all of the IDE's code navigation works fine.
You can't easily replace the C++ compiler in Visual Studio.
But at one time (in the 1990's) I used Visual Studio as simply an editor for Java. And since there are extensions for e.g. the D programming language (well that's the only one I've used) you can certainly, with a lot of work, make the full Visual Studio work with g++ or any other compiler for whatever language, as an additional "language". It can even work with the debugger, if the language implementation is suitable for that.
It's just that nowadays it's much easier to use an IDE that does support the tools you want to use. E.g., for g++ you have Eclipse, Code::Blocks, even old DevC++, etc. Oh yes, and the QT thing.

Build Visual Studio 6 project without Visual Studio

I have inherited a Visual Studio 6 C++ project. The project builds fine in Visual Studio 6 but I failed to compile certain files in the project with a gcc compiler. These issues relate to forward declarations and probably other issues. For the mean-time, I'm not interested in fixing these problems since the code is horrible. The code is also windows dependant since it uses win32 to communicate with com ports.
So, I wish to compile with an ms compiler (and build and link...) but I don't have access anymore to Visual Studio due to company policy...
What options are open to me?
THanks for your help,
Barry.
You can try downloading the free (as in beer) windows SDK. It's been a while, but I believe that these low level tools, such cl, link and make are available though these.
http://msdn.microsoft.com/en-us/windows/bb980924
But you probably will need to massage the code a little, so you might need to deal with the win api a little bit too.
Just to clarify, this is free and not associated with VS, so unless your company has some rather restrictive policies, you should be able to download and use the Windows SDK fine. Furthermore, the compiler tools should be somewhat friendly to VS6.

How to downgrade solution from Visual Studio 2010 to Visual Studio 2005?

I have a huge Visual Studio 2010 solution. I work with Visual Studio 2005, so I want to convert the solution to the desired version. Basically, it's a portable C++ code so it should compile on Visual Studio 2005 too. Changing the version in the *.sln file doesn't help because the *.vcxproj format is completely different from the old *.vcproj format.
Recreating the solution by hand is not an option because of its size. Also there may be some non-default compiler flags, dependencies, etc. that I don't know of (and I can't look through ALL this XML junk that I don't understand).
There is already a related question on How Do I Downgrade a C++ Visual Studio 2008 Project to 2005. However, the utility suggested there supports at most Visual Studio 2008.
Any suggestions?
It really totally sucks, that every proprietary IDE today thinks it needs to create its own project file format.
"Dear IDE developers, just use Makefiles and create a nice GUI for it so that also people without Makefile knowledge can use it!" In VS6 it was at least possible to import/export Makefiles, but not today anymore. And it was possible to use nmake for automated builds. No IDE needed to be installed, just the toolchain which could be grabbed by a simple checkout without installation.
I use CMake now. It's free, it's cross-platform, it is well supported in free IDEs like KDevelop, QtCreator, etc. It can generate Makefiles and Visual Studio projects.
So you maintain only one project source, the CMakeLists.txt file and can work with any IDE. No pain with different versions of Visual Studio or with other proprietary project file formats.
This way you can generate or VS projects for developing and you can generate Makefiles for commandline builds using nmake like in the good old days.
BTW, it's much easier to change settings in a CMakeLists.txt than clicking through various GUI dialogs. But this is a matter of personal preferences.
In my work made a utility which utilized the EnvDTE.dll and scanned a vcproj-file and optionally all vcproj-files within a sln-file. It compared all settings with a "template" and would issue a warning or optionally update the setting to correct values. We used this utility so that settings would be verified to be correct and consistent throughout all projects. I haven't updated the utility to 2010 yet due to other priorities.
EnvDTE hasn't changed much from Visual Studio 2008 to Visual Studio 2010. Perhaps it is possible to create a simple utility which opens the vcxproj-file using DTE100 and saves it using DTE90, or earlier.
Easiest way is probably to create a new project in VS 2005, and use the add existing item dialog to add the code to the project. I'd suggest using 'Empty Project' as the project type, so you don't have a lot of rubbish autogenerated for you that you'll just delete anyway.
I haven't tried it, but this looks promising:
http://www.emmet-gray.com/Articles/ProjectConverter.htm
edit: Nope, not promising, sorry :-(

Visual Studio environment alternative

I use Visual C++ (7.1 and 8.0) on huge C++ project. The solution contains thousands of files. Visual Assist helps in jumping to function and class definitions. The problem is that it sometimes becomes too slow. I just can't edit a single letter without delay.
Is there some alternative to this environment? I mean something that may read .sln and .vcproj files, use MSVC debugger, compile with MSVC compiler or even use IncrediBuild if necessary. I don't need any sophisticated features. It should be possible to find and open a file by name and jump to function/class definition from place where it is used.
May be Vim with some plugins? Or something else?
It seems there is no alternative to MS Visual studio. I've added separate HDD for source files and it works much better.
Currently i left Visual studio because c++ support just sucks (still using Visual studio 2013 but only for C# projects)
i use NetBeans right now, and really enjoy the refactoring part.
The visual C++ compiler support can be added using a free plugin (VCC4N - Visual C++ Compiler For NetBeans)
good luck