English 中文(简体)
How to build LLVM using GCC 4 on Windows?
原标题:

I have been able to build LLVM 2.6 (the llvm-2.6.tar.gz package) using MinGW GCC 3.4.5. I haven t tested properly, but it seems to work.

The trouble is, I have libraries of my own which don t build using GCC3, but which work fine in GCC4 (template issues). I believe the first official GCC4 version for MinGW is GCC 4.4.0.

EDIT

Decluttered - everything useful in the "tried this tried that" info is now in the answer.

EDIT

Most of this question/answer is redundant with LLVM 2.7 - the standard configure, make routine works fine in MinGW with no hacks or workarounds.

最佳回答

If at first you don t succeed...

I can now build LLVM 2.6 using MinGW GCC 4.4.0, and it isn t too hard once you know how. I still cannot run the DejaGNU tests, though at first sight that shouldn t be that hard - most likely I ll need the CygWin packages for dejagnu and expect. I also haven t built llvm-gcc yet.

Before the step-by-step, here are the three problems...


Problem 1...

Attempting to build llvm using the standard build instructions fails with the following compiler error in Signals.cpp (win32/Program.inc)

llvm[1]: Compiling Signals.cpp for Release build
In file included from Signals.cpp:33:
Win32/Signals.inc: In function  LONG LLVMUnhandledExceptionFilter(_EXCEPTION_POINTERS*) :
Win32/Signals.inc:234: error: exception handling disabled, use -fexceptions to enable

The workaround is to use "make -k -fexceptions" - answer found in the pure language documentation.


Problem 2...

Even with the first workaround, the following compiler error occurs...

ExternalFunctions.cpp: In function  bool ffiInvoke(void (*)(), llvm::Function*, const std::vector<llvm::GenericValue, std::allocator<llvm::GenericValue> >&, const llvm::TargetData*, llvm::GenericValue&) :
ExternalFunctions.cpp:207: error:  alloca  was not declared in this scope

It seems that an option is being specified which disables the "alloca" built-in.

The workaround is to edit the problem file

C:llvm-2.6libExecutionEngineInterpreterExternalFunctions.cpp

Just after the "#include <string>" line, insert...

#define alloca __builtin_alloca


Problem 3...

Even with the compilation errors fixed, the example programs won t run. The run-time errors are...

Assertion failed: errorcode == 0, file RWMutex.cpp, line 87

This relates to the use of the pthreads library, in the following lines of RWMutex.cpp

86:   // Initialize the rwlock
87:   errorcode = pthread_rwlock_init(rwlock, &attr);
88:   assert(errorcode == 0);

The basic issue is that pthreads support is included in MinGW GCC, and included in the builds of AFAICT all the GCC4 variants - including the unofficial TDM builds, as well as including MinGW GCC 4.4.0. This was not included with MinGW GCC 3.4.5, which is why LLVM builds fine with default options on that compiler. Using 4.4.0, the LLVM configure script detects the pthreads support and uses it - but the pthreads-w32 library used seems not to be fully compatible.

One workaround is to delete the following files from mingw gcc 4.4.0 as suggested in http://markmail.org/message/d7zw2zjq7svevsci - yes, I know I previously said they weren t there, but I had my folder layout confused...

  • mingw32includepthread.h
  • mingw32includesched.h
  • mingw32includesemaphore.h
  • mingw32liblibpthread.a

It is better, though, to simply tell the configure script to disable threads...

./configure --disable-threads


So, the steps are...

First, install the following MinGW and MSYS packages...

  • binutils-2.20-1-mingw32-bin.tar.gz
  • mingwrt-3.17-mingw32-dev.tar.gz
  • mingwrt-3.17-mingw32-dll.tar.gz
  • w32api-3.14-mingw32-dev.tar.gz
  • gcc-full-4.4.0-mingw32-bin-2.tar.lzma
  • make-3.81-20090914-mingw32-bin.tar.gz
  • tcltk-8.4.1-1.exe
  • MSYS-1.0.11.exe
  • msysDTK-1.0.1.exe
  • bash-3.1.17-2-msys-1.0.11-bin.tar.lzma
  • bison-2.4.1-1-msys-1.0.11-bin.tar.lzma
  • flex-2.5.35-1-msys-1.0.11-bin.tar.lzma
  • libregex-0.12-1-msys-1.0.11-dll-0.tar.lzma

This package list may be more than needed - in particular tcl tk is only needed for the DejaGNU tests, which I haven t got working yet.

Make sure that the in folder of your MinGW install is on the PATH (Control Panel, System, Advanced, Environment Variables).

Extract llvm-2.6.tar.gz

Edit the file C:llvm-2.6libExecutionEngineInterpreterExternalFunctions.cpp, and just after the line "#include <string>", add the line

#define alloca __builtin_alloca

Start an MSYS command prompt, and run...

cd /c/llvm-2.6
./configure --disable-threads
make -k CXXFLAGS=-fexceptions

I m assuming you extracted llvm to c:llvm-2.6

Handy hint - try "./configure --help"

Consider the --enable-targets=host-only and --enable-doxygen configure script options in particular.

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签