How do I compile on Visual C++?

From LLVM

Jump to: navigation, search

Last updated: 2009-10-28 (LLVM Release 2.6)

  1. Using CMake:
    1. Under "Where is the source code:" enter the location of the 'llvm-2.5' directory
    2. Under "Where to build the binaries:" enter another location such as 'llvm-2.5-msvc'. This location will store the MSVC++ specific solution/project files.
    3. Click Configure and a dialog will pop up asking you to select a compiler. Choose the appropriate Visual C++ version.
    4. After processing is done, click Configure once more
    5. After processing is done, click Generate
  2. Open 'llvm-2.6-msvc\LLVM.sln' and build

If you want to copy the includes/libs elsewhere to make a stable copy of these directories:

  1. Copy 'llvm-2.6\include' to the new include directory, e.g. 'llvm-include'
  2. Copy 'llvm-2.6-msvc\include' over the top of the new 'llvm-include' directory
  3. Copy 'llvm-2.6-msvc\Debug' or 'llvm-2.6-msvc\Release' to the new lib directory 'llvm-lib'

You can also set the variable CMAKE_INSTALL_PREFIX when you invoke cmake to a directory where you want LLVM installed. Then, build the "install" target.

Contents

[edit] Visual C++ 2010 beta 2 Workarounds

Note: These workarounds are all dirty hacks! As they change the LLVM source itself, they may introduce new bugs which are not the fault of the original authors of LLVM. Only use these if you understand what is happening.

Note 2: These hacks may become unnecessary in later versions of LLVM or when VC++ 2010 is properly released. Check the problems exist before you try to fix them.

[edit] "error C2668: 'llvm::next' : ambiguous call to overloaded function"

The LLVM function 'next' has a name conflict with a new function in the VC++ standard libraries. To resolve this, do a solution-wide Find & Replace of 'next(' with 'llvm::next(' and then 'llvm::llvm::next(' with 'llvm::next('. Make sure to select 'Match case' and 'Match whole word'. Also, as of LLVM 2.6, most header files are no longer included inside the solution file, so you may have to manually change these header files.

[edit] "error C2039: 'setjmp' : is not a member of 'llvm::Intrinsic'"

The enumeration member Intrinsic::setjmp no longer behaves as intended because 'setjmp' is now a C++ Macro in Microsoft's standard libraries. A workaround is to replace all instances of 'Intrinsic::setjmp' with 'Intrinsic::_setjmp' (MSVC's new 'setjmp' macro expands to '_setjmp' on 32 bit platforms. If this still doesn't work, replace 'setjmp,' with '_setjmp,' in 'llvm-2.6-msvc\include\llvm\intrinsics.gen'.

[edit] "error C2440: 'return' : cannot convert from 'const llvm::SuccIterator<Term_,BB_>' to 'llvm::succ_iterator &'"

The problem lies somewhere in 'llvm-2.6\lib\Transforms\Utils\SimplifyCFG.cpp:71':

  assert(std::find(succ_begin(ExistPred), succ_end(ExistPred), Succ) !=
         succ_end(ExistPred) && "ExistPred is not a predecessor of Succ!");

A workaround is to comment this assert out. As asserts are ignored in Release mode anyway, this shouldn't cause any previously working code to break.

[edit] "error C2248: 'llvm::EquivalenceClasses<ElemTy>::ECValue::ECValue' : cannot access private member declared in class 'llvm::EquivalenceClasses<ElemTy>::ECValue'"

A workaround is to make the ECValue class public at by inserting 'public:' before 'llvm-2.6\include\llvm\ADT\EquivalenceClasses.h:67'

Alternative Workaround

Another, possibly better, workaround is to change 'llvm-2.6\include\llvm\ADT\EquivalenceClasses.h:67' to read:

  class ECValue {
    friend class EquivalenceClasses;
    template<class T>               //add this line
    friend class std::allocator;    //add this line

[edit] "error C2440: 'initializing' : cannot convert from 'int' to 'llvm::StoreInst *'"

Related error: "error C2439: 'std::_Pair_base<_Ty1,_Ty2>::second' : member could not be initialized" Caused at 'llvm-2.6\lib\Transforms\Utils\PromoteMemoryToRegister.cpp:837'

    StoresByIndexTy::iterator I = 
      std::lower_bound(StoresByIndex.begin(), StoresByIndex.end(),
                       std::pair<unsigned, StoreInst*>(LoadIdx, 0),
                       StoreIndexSearchPredicate());

Fix: Replace '(LoadIdx, 0)' with '(LoadIdx, nullptr)' or '(LoadIdx, (StoreInst*)0)'

[edit] "error C2440: 'initializing' : cannot convert from 'int' to 'const llvm::TargetRegisterClass *'"

Related error: "error C2439: 'std::_Pair_base<_Ty1,_Ty2>::second' : member could not be initialized" Caused at 'llvm-2.6\lib\CodeGen\SelectionDAG\TargetLowering.cpp:2322'

    return std::pair<unsigned, const TargetRegisterClass*>(0, 0);

And also at 'llvm-2.6\lib\CodeGen\SelectionDAG\TargetLowering.cpp:2354'

    return std::pair<unsigned, const TargetRegisterClass*>(0, 0);

Fix: Replace '(0, 0)' with '(0, nullptr)' or '(0, (const TargetRegisterClass*)0)' on both of these lines

[edit] "error C2589: '(' : illegal token on right side of '::'"

This occurs around the use of 'std::min' and 'std::max' and creates errors in 'stringref.h' and 'targetinstritineraries.h'.

This occurs because 'min' and 'max' are defined as macros in "WinDef.h", which isn't included by LLVM but may be included by one of your own source files.

Fix: Put '#define NOMINMAX' in your own source files before any Windows related header is imported.

Personal tools