0

我正在開發使用某些標準C++庫的Portable Native Client應用程序,例如iostream和fstream。當我包括這些標題,並嘗試與Visual Studio編譯該項目2012 Pro中,許多錯誤拋出:PNaCl - 編譯錯誤「僅支持Win32目標」

enter image description here

根據本機客戶端的文檔,有可能在PNaCl項目中使用C++標準庫。 有沒有人遇到過這個問題或知道如何解決它?

編輯:

@rubenvb:我不認爲我是一種編譯64 ..我的目標配置調試\ PNaCl。

@JF Bastien:我使用SDK附帶的編譯器。編譯器調用:

C:\nacl_sdk\pepper_39\toolchain\win_pnacl\bin\pnacl-clang.bat -o PNaCl/newlib/Debug/decompressor_prototype.obj -DNACL -ID:/dev/hello_nacl_cpp/charls -I"C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/include" -Iinclude -Iatlmfc/include -IC:/nacl_sdk/pepper_39/toolchain/win_pnacl/usr/local/include -IC:/nacl_sdk/pepper_39/toolchain/win_pnacl/usr/include -IC:/nacl_sdk/pepper_39/toolchain/win_pnacl//lib/clang/3.4/include -IC:/nacl_sdk/pepper_39/include -fexceptions -MMD -g -O0 -c decompressor_prototype.cpp 

下面是錯誤的文本版本:

1>------ Build started: Project: decompressor_prototype, Configuration: Debug PNaCl ------ 
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppBuild.targets(343,5): warning MSB8003: Could not find VCInstallDir variable from the registry. TargetFrameworkVersion or PlatformToolset may be set to an invalid version number. 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\crtdefs.h(44,2): error : ERROR: Only Win32 target supported! 
1>NACLCOMPILE : #error error : Only Win32 target supported! 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\vadefs.h(19,2): error : ERROR: Only Win32 target supported! 
1>NACLCOMPILE : #error error : Only Win32 target supported! 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\crtdefs.h(470,18): error : 'short wchar_t' is invalid 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\crtdefs.h(470,1): warning : typedef requires a name [-Wmissing-declarations] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\crtdefs.h(506,9): error : unknown type name '__int64' 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\yvals.h(509,9): error : unknown type name '__int64' 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\yvals.h(510,19): error : expected ';' after top level declarator 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\yvals.h(575,2): warning : calling convention '__thiscall' ignored for this target [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\yvals.h(576,11): warning : calling convention '__thiscall' ignored for this target [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\yvals.h(577,2): warning : calling convention '__thiscall' ignored for this target [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\yvals.h(709,5): warning : calling convention '__thiscall' ignored for this target [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\yvals.h(710,2): warning : calling convention '__thiscall' ignored for this target [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(445,33): error : redefinition of '__int64' as different kind of symbol 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(445,40): error : expected ';' after top level declarator 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(445,88): error : expected ')' 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(445,49): error : C++ requires a type specifier for all declarations 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(471,77): error : expected ')' 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(472,91): error : expected ')' 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(477,33): error : redefinition of '__int64' as different kind of symbol 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(477,40): error : expected ';' after top level declarator 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(477,49): error : C++ requires a type specifier for all declarations 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(478,33): error : redefinition of '__int64' as different kind of symbol 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(478,40): error : expected ';' after top level declarator 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(478,49): error : C++ requires a type specifier for all declarations 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(619,111): warning : __declspec attribute 'restrict' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(619,99): warning : __declspec attribute 'noalias' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(620,29): warning : __declspec attribute 'noalias' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(620,29): warning : __declspec attribute 'noalias' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(621,104): warning : __declspec attribute 'restrict' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(621,92): warning : __declspec attribute 'noalias' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(623,88): warning : __declspec attribute 'restrict' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(623,76): warning : __declspec attribute 'noalias' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(625,92): warning : __declspec attribute 'restrict' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(625,80): warning : __declspec attribute 'noalias' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(626,29): warning : __declspec attribute 'noalias' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(626,29): warning : __declspec attribute 'noalias' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(627,85): warning : __declspec attribute 'restrict' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(627,73): warning : __declspec attribute 'noalias' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(628,85): warning : __declspec attribute 'restrict' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(628,73): warning : __declspec attribute 'noalias' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(630,88): warning : __declspec attribute 'restrict' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(630,76): warning : __declspec attribute 'noalias' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(632,92): warning : __declspec attribute 'restrict' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(632,80): warning : __declspec attribute 'noalias' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(634,88): warning : __declspec attribute 'restrict' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(634,76): warning : __declspec attribute 'noalias' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(636,92): warning : __declspec attribute 'restrict' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(636,80): warning : __declspec attribute 'noalias' is not supported [-Wignored-attributes] 
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdlib.h(713,77): error : expected ')' 
1>NACLCOMPILE : fatal error : too many errors emitted, stopping now [-ferror-limit=] 
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ========== 

回答

3

tl; dr:下降大部分-I包括。

C++標準庫可以與PNaCl一起使用,但不是所有的實現都可以使用!您明確告訴編譯器使用Visual Studio的標準庫實現(使用-I選項),但不需要執行此操作:默認情況下,PNaCl編譯器將鏈接到libC++(並且我們有對libstdC++的傳統支持,但是我不建議使用它)。

這不只是具備的問題:

  • C++庫依靠C庫,並PNaCl假定newlib使用(我們也有仿生實驗性支持,並很快的glibc)。
  • C++庫依賴於鏈接到程序中的運行時函數。這將自動發生,但不適用於Visual Studio的包含,因爲它們沒有相同的運行時間。

我看到你還包括ATL MFC,我不確定它也能工作。

+0

刪除VisualStudio特定的包含程序確實解決了問題。 IntelliSense抱怨缺少類型,但正在編譯。謝謝你的幫助 :) – Signum 2015-02-12 09:43:18

0

你正在編譯爲64位(x64),並且不支持PNaCl,或使一些#error在你沒有向我們展示的一些標題(因爲你剔除了大部分錯誤)正在告訴你。

但是,爲什麼__int64會觸發一個錯誤,我不知道,因爲這是一個MSVC builtin type。此外,請使用<cinttypes>std::int64_t(可選)或std::int_least64_t(始終可在符合的實施中使用)。

+0

我已更新我的帖子,添加了「錯誤列表」截圖。 – Signum 2015-02-05 14:59:58

+0

@Signum:嘗試獲取錯誤的文本格式(在構建日誌中,最有可能)。我無法在你的屏幕截圖中查出一半字母。 – rubenvb 2015-02-05 15:42:46

+1

你使用什麼編譯器?你不能使用Visual Studio自己的編譯器,你必須使用SDK附帶的pnacl-clang ++(但你可以從Visual Studio UI調用pnacl-clang ++)。請提供編譯器調用信息的錯誤文本版本。 – 2015-02-05 16:06:42