Unix Makefile in Windows Visual Studio 2008 - c++

I've done a decent search, but can't seem to find a way to get Visual Studio 2008 to use a unix Makefile, or even to create some MSVC compatible equivalent from the Makefile. Does anyone have ideas or similar issues?
Note: I already know the benefits/drawbacks of using Makefiles or not, and I don't want to hear your opinion. All I'm interested in right now is creating a Windows library from some originally unix code which only has a Makefile, and getting something functional out of it.
TIA.

You can also use cccl with make for windows.
cccl is a wrapper around Microsoft
Visual C++'s cl.exe and link.exe. It
converts Unix compiler parameters into
parameters understood by cl and link.

What you can do is create a project from existing code. Visual C++ does a pretty good job at compilation without makefiles.
You could also install MinGW and that has make and the compilers.
http://www.mingw.org/

Use the nmake commandline tool. Note it doesn't support everything that GNU Make does so you may need to edit the Makefile to make it compatible but it's the closest thing to what you want.

Typically what I see people do is use them the other way around: Use make as the master build system and have it invoke Visual Studio to build its stuff in batch mode.
I don't have 2008 on me, but w/ VisualStudio2005 you can build a solution with a rule something like this
release = "Win32 Debug"
progname.exe : progname.sln
devenv $< /Rebuild /"$(release)/"
(Note: I had to use spaces in this example, as tab just takes me to the next field.)

Related

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.

How to compile c++ libs using Microsoft C++ compiler without the IDE

I want to use Notepad and invoke the compiler and linker from the command prompt.
No IDE no make , nmake or anything like similar because I want to know the exact syntax required to do the following:
1. create a static library
2. create a dll
Yes, I have browsed the MSDN site but the examples I saw assume one is using the IDE which does a lot of setup behind the scenes
Pls Note: I know how to compile executables using cl also setting up the env using vcvarsall.bat. My question is about compiling static libraries and dlls.
I am using Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86.
Suggestions on to use some other compiler ( gcc, mingw, intel etc.) will not be helpful at the moment.
The C++ compiler is named cl. The compiler options are well-documented on MSDN. The linker is named link. The linker options are also well-documented on MSDN.
You'll need to run vcvarsall.bat to be able to build with the Visual C++ toolchain; this batch file sets up all the required environment variables and such. If you've installed Visual Studio, you should have a shortcut on your Start Menu entitled "Visual Studio Command Prompt." This shortcut will get you a command prompt and run that batch file.
For DLLs, pass the /c flag to cl.exe (which compiles but doesn't link), and pass the /DLL flag to link.exe. Instead of making an executable, it makes a DLL.
For static libraries, use the lib.exe program.
There are multiple approaches, all of which are handily documented in one place:
Visual C++ Concepts: Building a C/C++ Program
Building on the Command Line
Note that the build system completely changed between VC++ 2008 (which you're using) and VC++ 2010 (which is the current release).
A couple of minor things to add.
Personally I wouldn't use Windows batch files.
I would use nmake http://msdn.microsoft.com/en-us/library/dd9y37ha(v=vs.71).aspx building outside of visual studio is nmake's day job and that's the standard way to build visual studio projects for release say on a build machine, rather than in a development environment.
The other thing in nmake's favour is that if cross-platform is important to you then cmake ( http://www.cmake.org/ ) is a brilliant tool for dynamically creating Windows nmake files and non-Windows make files and it comes with ctest for running your unittests and selftests.
Advert over.

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 :-(

Simultaneus development in Visual Studio and a Linux IDE

I am trying to get started with an existing open source project (QuantLib) using Linux operating system. However it seems that most developers use Visual Studio (judging from the project files committed with the source).
Which Linux C++ IDE would be most compatible with VS project files? Is there a way to import/export them, so that I don't have to create my own projects from scratch (and update them every time someone adds a new file)?
EDIT: Its all unmanaged code
In my experience, the best method for doing dual-development on Linux & Windows is to throw away the existing Visual Studio project files and, instead, use CMake to generate the platform-specific build environment. It's capable of outputting Nmake makefiles (for command-line Windows builds), Visual Studio projects, and Linux makefiles. The documentation leaves a bit to be desired but once you have it up and running, it's very easy to maintain.
The FAQ provides installation instructions for MinGW. It seems that there is a GNU Makefile included, so you don't need to mess with Visual Studio project files.
Aparantly they they only build on MAC and Windows.
Instructions here: http://quantlib.org/install/macosx.shtml
But since MAC is basically BSD Unix it should be identical (or with little trouble) to get it up and running on Linux.
The following should work (though you may need to look at the configure options)
1) Install Boost.
2) ./configure
3) make
You'll definitely want to check out Mono, it might be just what you're looking for: http://monodevelop.com/

Cygwin in Visual Studio

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/