build toolchain with cmake, clang and llvm for visual studio - c++

I googled a lot and didn't find an appropriate answer, so I'm asking here.
What steps do I need to take to develop a c++ project from existing code which shall be compiled using cmake and clang?
I also want to have all the nice features like auto-completion and debugging with breakpoints and step by step debugging.

See the recent LLVM snapshot page for Windows builds integrating with Visual Studio here. There is an installer and a code formatting plugin. You will not get auto-complete and Clang/LLVM has nothing to do with debugging in Visual Studio (except that it will probably not work if you compile with Clang).
See also this interesting blog post predicting much good for LLVM on Windows in the future, backed by companies with paid developers ;-)

Staying on top of what the clang guys are doing for Windows is a good idea. The last two releases 3.6 and 3.7 show a commitment to the product but still some holes: MSVC C++: /Z7 but not quite /Zi debug information, not quite compatible with MSVC C++ exceptions (but Windows SEH works) meaning this is more like an auxiliary build tool at the moment than something you can build any running product on. I concur with the problems with exceptions at the moment.
I haven't got the strakh to post more than two links but the intervening weekly notes, have lots of interesting snippets including the coming of lldb to Windows and (if you care for this sort of thing) a longer post on compiling for CLR on Windows. Either way, looking at blog.llvm.org regularly is a good idea to keep this answer current.

Related

LLVM 3.4 integration with VS 2012

I have read online documentations and built LLVM using Cmake and visual studio using Getting Started with the LLVM System using Microsoft Visual Studio. I could not find how to use the LLVM tooolchain on an existing visual studio project. I am new to this environment and would appreciate any help.
EDIT 1 : I am contributing to a project, where I am required to build an Interpreter. The project restricts me to code in VS.
Here are the errors when I try to integrate LLVM and VS, I must be doing something terribly wrong LLVM compilation errors on VS 2012
EDIT 2: I am unclear as to how should we integrate LLVM in an existing VS project after a successful LLVM build (and installation on system).
EDIT 3: I aim to develop my own language utilizing clang/llvm. I cant figure out how to do this sitting in the VS enironment.
The instructions you have followed are not supposed to produce a "plug-in replacement for Visual Studio's provided compiler", but a way to, generally, build LLVM+CLANG - and of course, unless you are wanting to spend a lot of work [1], to build a compiler written in C++, you need an existing C++ compiler - and the instructions show how to do that with Visual Studio. You then have a clang and clang++ compiler and tools on your system, but it's not meant for "use it within Visual Studio".
From what I can tell from past experience, the Visual Studio compiler is not trivially replaceable, but you can of course use a Makefile Project to compile anything in any way you like.
This discussion from MS does provide another solution, but again, it's not a "instant plug in" solution:
http://social.msdn.microsoft.com/forums/vstudio/en-US/b9610ed2-e8ae-48c9-864c-e3d12af97b05/support-an-alternative-compiler
Some further googling shows this up:
https://github.com/ishani/ClangVSx
I have no idea if that works well or not - it seems to "only" support clang 3.3, where the current release is 3.4 and the "latest" is pre-3.5. I doubt there's a huge amount of difference, but I'm also not sure that there's "no difference".
[1] You can "bootstrap" a compiler from nothing, but it's really quite a lot of work writing a small compiler that can do a subset of the language, repeat this several times, to eventually compile the actual compiler in a more full compiler - and LLVM is not even nearly designed for that in the first place.

Is there an open source for free tool for MS Visual C++ Express to build using gcc?

While the Microsoft compiler typically builds faster code, I'm in an environment where building Linux applications with gcc is required. I prefer MSVS and the Express versions as my IDE and have been able to configure it such that Intellisense and all the other nice features are working. However, I have been unable to find an easy way to get VC++ Express 2010 to build using gcc. I'm not sure if I remember correctly, but I thought about half a decade ago there was support to switch compilers when using MSVS.
I have found an extension to download claiming to do this, but it costs about $50. Does anybody know of any free or open source tools that can accomplish the above?
Try CMake: http://www.cmake.org/. It is a cross-platform, cross-ide build system. It will generate
VS project for you, and ordinary makefiles (or eclipse, or what you need).
Then, use VS to edit the code, and "make" to build it. I did it myself to develop windows + linux on virtual machine. And it worked fine.
As I realize there are no plugins, but you could simply setup some custom build rules and make gcc compile your project instead of the cl.
Google for the Custom build rules in Visual Studio / provide your own makefile. Also note that if you wish to still have the ability to debug your applications, you should probably look for something like WinGDB.
The good thing in this approach is that you can switch your configurations from cl to gcc, for example and easily test if your application remains compilable in both of them.
Still, the best way would probably be to use some automatic building tools like cmake or scons, which simplify the process greatly and can help you to switch to any other IDE in a matter of minutes.
Personally I like scons, because it's python-driven, but cmake is very nice to start from.

Is there a way to debug with the visual studio command prompt?

I've got a project that I need to get working with 3 compilers (Borland, gnu, and Microsoft). It works on 2/3 and now I just need to get it working with Microsofts. It seems to crash in places where it works fine with the other compilers, so I'm wondering if there is a way to debug with the command line, maybe to get a stack trace or get the line which caused the crash, something similar to gdb with gnu.
(Full disclosure: I work on the Visual Studio team)
If you're using the Microsoft C++ compiler, do you have Visual Studio installed already? If so, you can use the built-in debugger. If not, I would recommend trying Visual C++ 2010 Express for free. It has an excellent native debugger. You can break on first chance exceptions (C++, SEH, Win32 exceptions) and go right to the line where it happened along with the call stack, locals, etc.
Debugging Tools for Windows - an outstanding package of debugging tools that includes the cdb and ntsd console debugger (in addition to the GUI WinDBG debugger).
The package has fantastic docs, can easily be set up to be the 'just in time' debuggers that handle a crash, and works very very nicely with crash dumps.
These are the hardcore debugging tools that Microsoft uses for crash analysis (and more).
Note that Windows comes with a version of ntsd debugger (at least it used to - looks like it's not on my Win7 box outside of the tools package installation), but it's a great idea to get the package anyway so you have the latest tools - and like I said the docs are a wealth of great information.
Yes.
C++ : Building on the Command Line
C# : See Debug-Centric Options of csc.exe.
Well, you are having trouble with the one compiler that tries very hard to crash your program on purpose. It's called "Run-time error checks", the /RTC option compile option. You can turn it off to make it behave like those other ones. Or you could pursue the "something's wrong here" angle. It's well documented in the MSDN Library article for /RTC.
Codeview is an older product which does that, but there's no reason why you couldn't use visual studio to do the same thing.

Setting up windows for C++

To quote the FAQ, 'No question is [...] too "newbie"'
What is the best way to set up an Windows system (vista, if that matters) to work with C++?
Preferably with a nice IDE, easy compiling of software (support for make files, etc.), but suitable for a beginner.
I would quite like the IDE to use a relatively portable format, such as makefiles and configure scripts, nothing too proprietary.
I would also like the ability to add new libraries etc. without much hassle, and work with the majority of C++ code others have written.
I am comfortable using the command line.
Thanks for the help, hopefully the question is clear. And apologies if it's already been answered, i did have a look for similar questions.
I know this is not exactly 'nothing to proprietary' but you should give a look at the free Express Edition of Visual C++. Under its covers you'll get all the familiar make and command line tools, but wrapped in a polished IDE.
If you're really comfortable with the command line then you can make an IDE from code editor on top of a compiler/debugger suite. MS's own command line tools come with the platform SDK (free) and you get an awesome debugger in Windbg. My personal favorite code editor is Code Insight. I wish so hard for a Mac version /sigh.
Microsoft's Visual Studio has a free express edition which contains pretty much everything you need to program c++.
For a Gui, the main choices are probably, MFC (old and ugly), CLR/.Net (new and confusing) or look at Qt(now LGPL) or wxWigets
There are quite a few good IDEs for C++ available on Windows.
The de-facto standard for professional software development is Microsoft's Visual Studio, which is available in different versions, like the free Express Editions. This will give you a great tool-chain for Windows development.
However, for a more "cross-platform" approach, you should have a look to the free Eclipse C++ Development Tooling, which is available for many platforms. As long as your own code is platform-independent, the whole project can be shared between Windows, Linux, Mac, etc.
Other alternatives are MinGW or CygWin that both allow to use the GCC toolchain on Windows.
Try the MinGW compiler, it will come with a C and C++ compiler, Make, etc--among many others. This can be used from the command line, pretty easily: g++ -o someprogram.exe somecode.cpp
As for an IDE, there are lots out there. Right now I am using Code::Blocks, and so far it's been really nice. As well, it already supports the GCC compiler, and sets many of the appropriate flags for you, so all you'll really need to do is hit the "build" button.
Some others you might want to try are Eclipse, which is really powerful, but lots of its "power" will be really confusing and difficult to use until you start getting used to it. Visual C++ is another one, which (obviously) would integrate very nicely into Windows. Of course, you could always use emacs :)
I suggest you evaluate CodeBlocks.
Microsoft's Visual Studio is powerful but rather proprietary. If you prefer open/portable stuff, I recommend Dev-C++ and Cygwin.
FWIW, I recently went through this and tried the VC++ Express and QT Creator based stuff. Coming from a linux/unix background I found that QT was a little better since it was using the Ming compilers and some make based constructs.
If you will only be hacking for windows I would go for Visual Studio. It will definitely save you time you can spend on coding instead. Most open source out there for windows either already have VC project, and if they don't it is usually very simple to set one up. And normally they have either make or nmake files for you to build VC compatible libararies to link with.

Need a c++ compiler to work with libraries (boost, ...)

Currently I`m using Visual Studio for writing code in C++. But it seems so weighty that I decided to switch for another one, preferably free, not so strict to system resources (I mean memory, of course) as VS to learn libraries, such as Boost and Qt. What compiler do you suggest?
I'd suggest using Visual Studio's compiler from the command-line. You get the same high-quality compiler, without the resource-hogging IDE.
Although the IDE is pretty good too, and probably worth the resources it uses.
Code::blocks is exactly what you are after. You can can download it here: http://www.codeblocks.org/downloads/5
Choose the version with the mingw compiler bundled with it (Windows port of GCC). You can switch between that and the VC++ compiler as and when you like.
Code::Blocks has all the stuff you want, debugger integration, code completion, class browser, todo list etc. etc. It even import visual C++ projects.
Don't use Dev C++ which has already been recommended. It's very very old and outdated.
If you want to learn unix tools download and install cygwin It's a good set of tools but a full install takes up 5 or 6 gigs because so much is included.
There is always Digital Mars. Also, you can freely download Microsoft WDK
which comes with their C/C++ compiler and command-line build system.
You will be hard-pressed to find an IDE as capable as MS VS. It is incredibly feature-rich.
However, if you just want command line compiling and linking it can do that too.
GCC is also an option.
Please note that you do not need another compiler or IDE to use boost libraries. I wouldn't replace Visual Studio with any other IDE/compiler, at least not on Windows. Installing Cygwin or SUA (better than Cygwin, closer to the Windows Kernel) will only be a pain just for what you are trying to reach.
Try to minimize the memory usage by disabling unnecessary things, keep the amount of open source files small, use an alternative to document explorer to find help (your browser on msdn will do). Besides that, I wouldn't call a few ten megabytes of memory a high usage. As long as it doesn't slow your system down there is not a real issue.
A better idea would be to upgrade your computer rather than to replace something powerful with something that you don't know.
Seriously there is no real alternative to Ms's compiler on Windows. All the others are OK if you can't spring for Visual Studio or if you are just doing hobbyist work. Cygwin can be a pain to deal with.
If you don't want the IDE as someone else suggested just use the command-line compiler.
I've found VS to be quite good for doing Boost + Qt work. Especially if you have the Qt + VS integration tool. You get a GUI designer and respectable Qt project management tools.
If you are looking for a compiler that uses fewer system resources than the MS ones, you'll probably find that most modern compilers that are able to compile a good part of or almost everything in Boost will be quite heavy on system resources, both processor usage and memory consumption. To a certain extent that's just par for the course when it comes to C++.
That said, I do like to have a second compiler around if I'm writing portable code as it's a lot easier to iron out portability issues when you can ensure that the code compiles in different environments. If you want to do all that on Windows, may Cygwin is worth a look. However it does seem that the GCC you get with Cygwin is not exactly what you'd call up to date.
The aforementioned Digital Mars compilers are well worth a look, Walter Bright (the guy behind them) has been writing C++ compilers for a long time and they're pretty good. I have used them off and on since the early nineties and I've always been happy with them. Not to mention that they always seemed noticeably faster than the Microsoft offerings, but I haven't got any recent measurements to back that up.
At the end of the day, most third-party tool vendors on Windows tend to target the MS environment so if you're writing C++ code professionally and need/want tools like leak detectors, you pretty much need to be able to build with the MS compilers, even if they aren't your main development environment.
I sugget , Netbeans.org
NetBeans IDE , download the Cygwin , follow one tutorial from http://www.netbeans.org for C++ confuguration at Netbeans IDE , just 2 steps.. and u are ok
autocomplete (faster than VS')
classes
and all... you want xD
It needs to mention about DevCpp. It is a simple UI wrap for gcc compiler (oh my, it is sounds like a tautology). It provides lightweight IDE but not so stable (so, its IntelliSense is somewhat buggy).
If you use Qt why not use their IDE, QtCreator, there is compiler, debugger and GUI designer. All comes in one nice package and works on Windows, Mac and Linux.
In my opinion it's better than Code::Blocks (also based on MinGW/GCC).