问题
I have a project the successfully builds using MinGW32 on Windows 8.1 using CodeLite. I am trying to change the compiler from MinGW32 to clang. However, after switching the compiler over I get the following error:
c:/MinGW/lib/gcc/mingw32/4.8.1/include/c++\bits/stringfwd.h:74:33: error: use of undeclared identifier 'char16_t'
...followed by many others of a similar nature. So, I tried making a simpler program to check if the program was simply in my code and I'd been 'lucky' with MinGW32.
The following program also exhibits the same error:
#include <iostream>
int main(int argc, char **argv)
{
std::cout << "Hello World" << std::endl;
return 0;
}
Within CodeLite, the following compiler options are set (these have not changed between compilers):
-g;-O0;-Wall;-std=c++11
I've also tried checking the Enable C++11 Standard (clang)
box at the workspace level, just to be sure.
After some searching on the internet, I found the following issue:
Build fails on clang errors. #762
As a result of this, I tried adding -fno-ms-compatibility
to my compiler options. This did seem to have an effect, as the compiler error changed to:
c:/MinGW/lib/gcc/mingw32/4.8.1/include/c++\bits/char_traits.h:391:7: error: cannot mangle this built-in char16_t type yet
I tried using a popular search engine to find a solution to this too, but all I could find was a reference to it inside a file called MicrosoftMangle.cpp. Here is the part which mentioned the error I encountered:
void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T,
SourceRange Range) {
// <type> ::= <builtin-type>
// <builtin-type> ::= X # void
// ::= C # signed char
// ::= D # char
// ::= E # unsigned char
// ::= F # short
// ::= G # unsigned short (or wchar_t if it's not a builtin)
// ::= H # int
// ::= I # unsigned int
// ::= J # long
// ::= K # unsigned long
// L # <none>
// ::= M # float
// ::= N # double
// ::= O # long double (__float80 is mangled differently)
// ::= _J # long long, __int64
// ::= _K # unsigned long long, __int64
// ::= _L # __int128
// ::= _M # unsigned __int128
// ::= _N # bool
// _O # <array in parameter>
// ::= _T # __float80 (Intel)
// ::= _W # wchar_t
// ::= _Z # __float80 (Digital Mars)
switch (T->getKind()) {
case BuiltinType::Void: Out << 'X'; break;
case BuiltinType::SChar: Out << 'C'; break;
case BuiltinType::Char_U: case BuiltinType::Char_S: Out << 'D'; break;
case BuiltinType::UChar: Out << 'E'; break;
case BuiltinType::Short: Out << 'F'; break;
case BuiltinType::UShort: Out << 'G'; break;
case BuiltinType::Int: Out << 'H'; break;
case BuiltinType::UInt: Out << 'I'; break;
case BuiltinType::Long: Out << 'J'; break;
case BuiltinType::ULong: Out << 'K'; break;
case BuiltinType::Float: Out << 'M'; break;
case BuiltinType::Double: Out << 'N'; break;
// TODO: Determine size and mangle accordingly
case BuiltinType::LongDouble: Out << 'O'; break;
case BuiltinType::LongLong: Out << "_J"; break;
case BuiltinType::ULongLong: Out << "_K"; break;
case BuiltinType::Int128: Out << "_L"; break;
case BuiltinType::UInt128: Out << "_M"; break;
case BuiltinType::Bool: Out << "_N"; break;
case BuiltinType::WChar_S:
case BuiltinType::WChar_U: Out << "_W"; break;
#define BUILTIN_TYPE(Id, SingletonId)
#define PLACEHOLDER_TYPE(Id, SingletonId) \
case BuiltinType::Id:
#include "clang/AST/BuiltinTypes.def"
case BuiltinType::Dependent:
llvm_unreachable("placeholder types shouldn't get to name mangling");
case BuiltinType::ObjCId: Out << "PAUobjc_object@@"; break;
case BuiltinType::ObjCClass: Out << "PAUobjc_class@@"; break;
case BuiltinType::ObjCSel: Out << "PAUobjc_selector@@"; break;
case BuiltinType::OCLImage1d: Out << "PAUocl_image1d@@"; break;
case BuiltinType::OCLImage1dArray: Out << "PAUocl_image1darray@@"; break;
case BuiltinType::OCLImage1dBuffer: Out << "PAUocl_image1dbuffer@@"; break;
case BuiltinType::OCLImage2d: Out << "PAUocl_image2d@@"; break;
case BuiltinType::OCLImage2dArray: Out << "PAUocl_image2darray@@"; break;
case BuiltinType::OCLImage3d: Out << "PAUocl_image3d@@"; break;
case BuiltinType::OCLSampler: Out << "PAUocl_sampler@@"; break;
case BuiltinType::OCLEvent: Out << "PAUocl_event@@"; break;
case BuiltinType::NullPtr: Out << "$$T"; break;
case BuiltinType::Char16:
case BuiltinType::Char32:
case BuiltinType::Half: {
DiagnosticsEngine &Diags = Context.getDiags();
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
"cannot mangle this built-in %0 type yet");
Diags.Report(Range.getBegin(), DiagID)
<< T->getName(Context.getASTContext().getPrintingPolicy())
<< Range;
break;
}
}
}
At this point, I am out of ideas on how to solve my problem, hence this question. Thank you in advance for any help you're able to give me!
Additional Information
I realise that I am still using the MinGW32 include directories here, and this in on purpose as this tutorial on CodeLite suggested I do so.
回答1:
To make things simpler: I am pretty sure that clang is not ready for Windows development. Other than code completion library, I have not seen a single production application successfully compiled with clang under MSW.
Note that I did manage to build a simple hello world, but it failed miserably when running it (especially when exception are involved)
Long story short: stick to MinGW (gcc) for Windows, its the most reliable thing you will get
Here the output of building a simple hello world with codelite on my machine (using clang 3.4 downloaded from LLVM website, and letting codelite detect it from settings->build settings->auto detect compilers):
C:\Windows\system32\cmd.exe /c "C:/MinGW-4.8.1/bin/mingw32-make.exe -j8 SHELL=cmd.exe -e -f Makefile"
"----------Building project:[ ClangHW - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'D:/src/TestArea/ClangHW'
D:/software/LLVM/bin/clang++.exe -c "D:/src/TestArea/ClangHW/main.cpp" -g -O0 -Wall -o ./Debug/main.cpp.o -Ic:/mingw-4.8.1/lib/gcc/mingw32/4.8.1/include/c++ -Ic:/mingw-4.8.1/lib/gcc/mingw32/4.8.1/include/c++/mingw32 -Ic:/mingw-4.8.1/lib/gcc/mingw32/4.8.1/include/c++/backward -Ic:/mingw-4.8.1/lib/gcc/mingw32/4.8.1/include -Ic:/mingw-4.8.1/include -Ic:/mingw-4.8.1/lib/gcc/mingw32/4.8.1/include-fixed -I. -I.
D:/software/LLVM/bin/clang++.exe -o ./Debug/ClangHW @"ClangHW.txt" -L.
mingw32-make.exe[1]: Leaving directory 'D:/src/TestArea/ClangHW'
0 errors, 0 warnings
It compiles fine, however, when I run it - it prints the "hello world" message and crashes instantly
Note that the reason that clang is using MinGW include paths, is simple: it does not come with its own header files, instead it relies on their existence (codelite uses your "default" MinGW compiler include paths and uses them for clang)
To conclude: I strongly recommend you to stick to MinGW or VC
Eran (Author of CodeLite IDE)
来源:https://stackoverflow.com/questions/25170594/changing-compiler-from-mingw32-to-clang-in-codelite-windows-results-in-compila