我使用在windows 10(32位操作系統,x86處理器)上從源編譯的clang 4.0.0。我試圖將我的cpp代碼編譯爲llvm格式爲ll的代碼。 下面是其無法使用鐺編譯示例代碼:Clang在windows下編譯錯誤++ 4.0.0
#include <windows.h>
#include <tlhelp32.h>
#include <fstream>
#include <mapi.h>
#include <memory>
#include<stdio.h>
/* Function to calculate x raised to the power y */
int power(int x, unsigned int y)
{
if (y == 0)
return 1;
else if (y%2 == 0)
return power(x, y/2)*power(x, y/2);
else
return x*power(x, y/2)*power(x, y/2);
}
/* Program to test function power */
int main()
{
int x = 2;
unsigned int y = 3;
printf("%d", power(x, y));
return 0;
}
這僅僅是一個示例代碼,但它是在所有的C++代碼,其中包括所列出的頭文件相同的行爲。 我用下面的命令將其編譯成LLVM IR代碼:
clang++ -S -emit-llvm assiral.cpp -o assiral.ll
在編譯時我收到以下錯誤:
C:\Sample>clang++ -emit-llvm -S assiral.cpp -o assiral.ll
In file included from assiral.cpp:3:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\fstream:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\includem:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\ostream:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\ios:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xlocnum:7:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\cmath:617:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xtgmath.h:9:
C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xtr1common:204:22: error:
use of undeclared identifier 'char16_t'
struct _Is_integral<char16_t>
^
C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xtr1common:210:22: error:
use of undeclared identifier 'char32_t'
struct _Is_integral<char32_t>
^
In file included from assiral.cpp:3:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\fstream:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\includem:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\ostream:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\ios:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xlocnum:10:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\streambuf:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xiosbase:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xlocale:8:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\stdexcept:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\exception:7:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\type_traits:6:
C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xstddef:257:2: error: 'auto'
return without trailing return type; deduced return types are a C++14 extension
auto _Unfancy(_Ptrty _Ptr)
^
In file included from assiral.cpp:3:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\fstream:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\includem:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\ostream:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\ios:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xlocnum:10:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\streambuf:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xiosbase:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xlocale:8:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\stdexcept:7:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xstring:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xmemory0:8:
C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\limits:612:33: error: use of
undeclared identifier 'char16_t'
template<> class numeric_limits<char16_t>
^
C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\limits:902:33: error: use of
undeclared identifier 'char32_t'
template<> class numeric_limits<char32_t>
^
In file included from assiral.cpp:3:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\fstream:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\includem:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\ostream:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\ios:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xlocnum:10:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\streambuf:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xiosbase:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xlocale:8:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\stdexcept:7:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xstring:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xmemory0:10:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xutility:8:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\utility:7:
C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\iosfwd:254:21: error: use of
undeclared identifier 'char16_t'
struct char_traits<char16_t>
^
C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\iosfwd:263:21: error: use of
undeclared identifier 'char32_t'
struct char_traits<char32_t>
^
In file included from assiral.cpp:3:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\fstream:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\includem:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\ostream:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\ios:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xlocnum:10:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\streambuf:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xiosbase:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xlocale:8:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\stdexcept:7:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xstring:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xmemory0:10:
C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xutility:698:2: error:
'auto' return without trailing return type; deduced return types are a C++14 extension
auto _Unchecked_n(_Iter _Src, _Diff)
^
C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xutility:742:2: error:
'auto' return without trailing return type; deduced return types are a C++14 extension
auto _Unchecked_n_backward(_Iter _Src, _Diff)
^
C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xutility:1142:12: error:
deduced return types are a C++14 extension
constexpr decltype(auto) _Operator_arrow(_Iterator&& _Target, false_type)
^
In file included from assiral.cpp:3:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\fstream:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\includem:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\ostream:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\ios:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xlocnum:10:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\streambuf:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xiosbase:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xlocale:8:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\stdexcept:7:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xstring:6:
C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xmemory0:356:2: error:
'auto' return without trailing return type; deduced return types are a C++14 extension
auto _Const_cast(_Ptrty _Ptr)
^
C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xmemory0:366:2: error:
'auto' return without trailing return type; deduced return types are a C++14 extension
auto _Const_cast(_Ty * _Ptr)
^
In file included from assiral.cpp:3:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\fstream:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\includem:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\ostream:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\ios:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xlocnum:10:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\streambuf:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xiosbase:6:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xlocale:8:
In file included from C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\stdexcept:7:
C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xstring:75:2: error:
statement not allowed in constexpr function
for (auto _Match_try = _Haystack + _Start_at; ; ++_Match_try)
^
C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xstring:119:3: error:
statement not allowed in constexpr function
for (auto _Match_try = _Haystack + _Min_value(_Start_at, _Hay_size - _Needle_size); ; --_Match_try)
^
C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xstring:144:3: error:
statement not allowed in constexpr function
for (auto _Match_try = _Haystack + _Min_value(_Start_at, _Hay_size - 1); ; --_Match_try)
^
C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xstring:169:3: error:
statement not allowed in constexpr function
for (auto _Match_try = _Haystack + _Start_at; _Match_try < _End; ++_Match_try)
^
C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xstring:188:3: error:
statement not allowed in constexpr function
for (auto _Match_try = _Haystack + _Min_value(_Start_at, _Hay_size - 1); ; --_Match_try)
^
C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xstring:213:3: error:
statement not allowed in constexpr function
for (auto _Match_try = _Haystack + _Start_at; _Match_try < _End; ++_Match_try)
^
C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\xstring:233:3: error:
statement not allowed in constexpr function
for (auto _Match_try = _Haystack + _Start_at; _Match_try < _End; ++_Match_try)
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
我希望在運行命令後已生成的字節碼文件(.ll文件)。我看過很多帖子,他們在其中引入了一個標誌:'-fms-compatibility-version = 19'以及命令。然而,添加的標誌被標記爲未知參數。我正在使用MSVS 2017.也許我錯誤地使用了這個標誌。但是我現在一直處於這種僵局。任何幫助或建議將不勝感激。
請包括一個最小的可編譯示例。 – OmnipotentEntity
感謝您更新您的問題。通過稍微修改源代碼來刪除Windows特定的頭文件,它在Linux下編譯得很好。這就是我開始排除故障的地方。嘗試重新安排您的內容並刪除不需要的內容。 – OmnipotentEntity
你究竟是什麼意思?由於標題問題,它沒有進入編譯階段。 –