0

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.

Community
  • 1
  • 1
Segmented
  • 2,024
  • 2
  • 23
  • 44
  • Take a look at [clang-cl](http://clang.llvm.org/docs/UsersManual.html#clang-cl) – nwp May 23 '14 at 08:34
  • @nwp I guess there is a bug which prevents me from walking this direction @ (http://stackoverflow.com/questions/20579216/clangvs2013-error-when-including-c-header-vs2012working) – Segmented May 23 '14 at 08:49
  • I was hopeful since a [clang-cl presentation](http://llvm.org/devmtg/2014-04/PDFs/Talks/clang-cl.pdf) said clang-cl has known problems but a fallback mechanism that compiles with cl if clang-cl fails. So in theory it should be able to always compile everything, with varying involvement of clang-cl and cl. – nwp May 23 '14 at 08:54
  • @nwp Thanks for pointing out. I guess I would take a look in detail to understand if this fulfills my requirements.. – Segmented May 23 '14 at 09:01
  • Are you actually talking about using clang to compile your code (which is what I answered) or "using clang/llvm to build your own language"? – Mats Petersson May 25 '14 at 09:47
  • @Mats Petersson I want to use clang/llvm to build my own language. That is my aim. I am unable to figure out how to utilize them siting in a VS environment. I must be doing something terribly wrong here. – Segmented May 25 '14 at 09:53
  • You should be able to do that by simply linking with the LLVM library. However, if you are making an interpreter, I'm not sure that's the best approach. Since I don't use VS (haven't done for the past 10 or so years), I can't really help on exactly how you go about configuring to link with llvm, but it should just be a list of libraries and include paths, essentially. – Mats Petersson May 25 '14 at 10:00
  • @Mats Petersson thanks. I have followed some approaches of linking llvm libraries as I found online but they simply won't work. I have already asked on the site regarding the errors that I get. Lets hope somebody guides me through as I am novice in this waters :) – Segmented May 25 '14 at 10:06

1 Answers1

3

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.

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
  • Thanks for the quick reply. My aim is to build an interpreter for this project. I am using winflexbison for the purpose, however I wanted to use LLVM to design the compiler. I have followed the tutorial @ [toy-compiler] (http://gnuu.org/2009/09/18/writing-your-own-toy-compiler/). I am looking for a way to do this from VS. – Segmented May 23 '14 at 08:15
  • Much like my project then, except I wrote my own parser (and I'm using Linux...): https://github.com/Leporacanthicus/lacsap – Mats Petersson May 23 '14 at 08:34
  • Thanks for providing the example... I am however restricted to use VS and the project I am contributing would be difficult to migrate to Linux... – Segmented May 23 '14 at 08:41
  • 1
    The purpose of the "example" was not for you to use it, just saying "I've done something similar" in general. – Mats Petersson May 25 '14 at 09:45