2010-08-18 61 views
1

在Linux環境中構建CLang之後,我嘗試在使用V​​isual Studio的Windows上構建它。一切都正確的,但,當我試圖編譯這個經典Hello World!程序使用叮噹編譯C++文件時出錯

#include <iostream> 

int main() 
{ 
    std::cout<<"Hello World!"; 
} 

我得到了很多錯誤

C:\Users\SUPER USER\Desktop>clang++ a.cpp 
In file included from a.cpp:1: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/i 
ostream:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/i 
stream:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/o 
stream:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/i 
os:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/x 
locnum:10: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/s 
treambuf:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/x 
iosbase:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/x 
locale:8: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/s 
tdexcept:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/e 
xception:38: 
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/eh.h(58) : error: 
     unknown type name 'type_info' 
_CRTIMP int __cdecl _is_exception_typeof(_In_ const type_info &_Type, ... 
                ^
In file included from a.cpp:1: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/i 
ostream:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/i 
stream:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/o 
stream:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/i 
os:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/x 
locnum:10: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/s 
treambuf:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/x 
iosbase:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/x 
locale:8: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/s 
tdexcept:7: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/x 
string:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/x 
memory:7: 
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/new(51) : error: 
     exception specification in declaration does not match previous declaration 

_Ret_bytecap_(_Size) void *__CRTDECL operator new(size_t _Size) ... 
            ^
note: previous declaration is here 
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/new(79) : error: 
     exception specification in declaration does not match previous declaration 

_Ret_bytecap_(_Size) void *__CRTDECL operator new[](size_t _Size) 
            ^
note: previous declaration is here 
In file included from a.cpp:1: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/i 
ostream:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/i 
stream:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/o 
stream:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/i 
os:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/x 
locnum:10: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/s 
treambuf:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/x 
iosbase:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/x 
locale:8: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/s 
tdexcept:7: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/x 
string:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/x 
memory:8: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/x 
utility:8: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/u 
tility:9: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/t 
ype_traits:7: 
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/xtr1common(355) : erro 
r: 
     rvalue references are only allowed in C++0x 
     struct _Remove_reference<_Ty&&> 
            ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/xtr1common(368) : erro 
r: 
     rvalue references are only allowed in C++0x 
     struct _Remove_rvalue_reference<_Ty&&> 
             ^
In file included from a.cpp:1: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/i 
ostream:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/i 
stream:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/o 
stream:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/i 
os:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/x 
locnum:10: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/s 
treambuf:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/x 
iosbase:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/x 
locale:8: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/s 
tdexcept:7: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/x 
string:6: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/x 
memory:8: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/x 
utility:8: 
In file included from C:\Program Files\Microsoft Visual Studio 10.0\VC\include/u 
tility:9: 
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits(243) : err 
or: 
     rvalue references are only allowed in C++0x 
     typedef _Ty && type; 
        ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits(427) : err 
or: 
     rvalue references are only allowed in C++0x 
     struct is_rvalue_reference<_Ty&&> 
            ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits(554) : err 
or: 
     '_From' does not refer to a value 
     struct is_convertible _IS_CONVERTIBLE(_From, _To) 
          ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits:554:40: not 
e: instantiated from: 
     struct is_convertible _IS_CONVERTIBLE(_From, _To) 
              ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits(553) : not 
e: 
     declared here 
template<class _From, class _To> 
      ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits(555) : err 
or: 
     expected class name 
     {  // determine whether _From is convertible to _To 
     ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits(720) : err 
or: 
     expected expression 
     struct has_nothrow_constructor _HAS_NOTHROW_CONSTRUCTOR(_Ty) 
            ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits:42:36: note 
: instantiated from: 
     : _Cat_base<is_pod<_Ty>::value || __has_nothrow_constructor(_Ty)> 
             ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits(721) : err 
or: 
     expected class name 
     {  // determine whether _Ty has a nothrow constructor 
     ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits(726) : err 
or: 
     expected expression 
     struct has_nothrow_copy _HAS_NOTHROW_COPY(_Ty) 
           ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits:44:36: note 
: instantiated from: 
     : _Cat_base<is_pod<_Ty>::value || __has_nothrow_copy(_Ty)> 
             ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits(727) : err 
or: 
     expected class name 
     {  // determine whether _Ty has a nothrow copy constructor 
     ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits(733) : err 
or: 
     expected expression 
     struct has_nothrow_default_constructor _HAS_NOTHROW_CONSTRUCTOR(_Ty) 
              ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits:42:36: note 
: instantiated from: 
     : _Cat_base<is_pod<_Ty>::value || __has_nothrow_constructor(_Ty)> 
             ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits(734) : err 
or: 
     expected class name 
     {  // determine whether _Ty has a nothrow constructor 
     ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits(739) : err 
or: 
     expected expression 
     struct has_nothrow_copy_constructor _HAS_NOTHROW_COPY(_Ty) 
              ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits:44:36: note 
: instantiated from: 
     : _Cat_base<is_pod<_Ty>::value || __has_nothrow_copy(_Ty)> 
             ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits(740) : err 
or: 
     expected class name 
     {  // determine whether _Ty has a nothrow copy constructor 
     ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits(746) : err 
or: 
     expected expression 
     struct has_nothrow_assign _HAS_NOTHROW_ASSIGN(_Ty) 
           ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits:46:36: note 
: instantiated from: 
     : _Cat_base<is_pod<_Ty>::value || __has_nothrow_assign(_Ty)> 
             ^
C:\Program Files\Microsoft Visual Studio 10.0\VC\include/type_traits(747) : err 
or: 
     expected class name 
     {  // determine whether _Ty has a nothrow assignment operator 
     ^
fatal error: too many errors emitted, stopping now [-ferror-limit=] 
20 errors generated. 

C:\Users\SUPER USER\Desktop> 

但是當我編譯相同Hello World程序作爲C文件寄託都去罰款。

#include <stdio.h> 

int main() 
{ 
    printf("Hello World!"); 
} 

C:\Users\SUPER USER\Desktop>clang a.c 

C:\Users\SUPER USER\Desktop>a.out 
Hello World! 

這裏的實際問題是什麼?

+0

狀態更新:仍然發生在叮噹2.8和vc10 – akira 2011-02-15 08:23:51

回答

1

看來鐺不開心,包括VC10頭文件。我會嘗試與VC9。

-4
#include "stdafx.h" 
#include <iostream> 
using namespace std; 
int main() 
{ 
    cout << "Hello World!\n" ; 
    return 0; 
} 

試試這一個,否則它可能是編譯器的問題...

+0

不知道爲什麼你認爲包括不存在'stdafx.h'是這裏的魔法子彈,但是......「。\ foo.cc(1):致命錯誤:'stdafx.h'找不到文件 #include「stdafx.h」 – akira 2011-02-15 08:23:11