PNaCl - 编译错误“仅支持 Win32 目标”

Posted

技术标签:

【中文标题】PNaCl - 编译错误“仅支持 Win32 目标”【英文标题】:PNaCl - compilation error "Only Win32 target supported" 【发布时间】:2015-02-05 14:46:38 【问题描述】:

我正在开发 Portable Native Client 应用程序,它使用一些标准 C++ 库,例如iostream 和 fstream。当我包含这些头文件并尝试使用 Visual Studio 2012 Pro 编译项目时,会抛出许多错误:

根据 Native Client 文档,可以在 PNaCl 项目中使用标准 C++ 库。 有没有人遇到过这个问题或者知道如何解决?

编辑:

@rubenvb:我不认为我正在为 x64 编译。我的目标配置是 Debug\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 ==========

【问题讨论】:

【参考方案1】:

tl;dr:删除大部分 -I 包括。

C++ 标准库确实适用于 PNaCl,但并非所有实现都适用!您明确告诉编译器使用 Visual Studio 的标准库实现(使用 -I 选项),但您不需要这样做:默认情况下,PNaCl 编译器将链接到 libc++(我们有对 libstdc++ 的传统支持,但我不建议使用它)。

这不仅仅是包含的问题:

C++ 库依赖于 C 库,而 PNaCl 假设使用了 newlib(我们还对仿生提供了实验性支持,很快就会支持 glibc)。 C++ 库依赖于链接到程序中的运行时函数。这将自动发生,但不适用于 Visual Studio 的包含,因为它们没有相同的运行时。

我看到您还包括 ATL MFC,我不确定它是否也能正常工作。

【讨论】:

删除 VisualStudio 特定的包含确实解决了问题。 IntelliSense 抱怨缺少类型,但它正在编译。感谢您的帮助:)【参考方案2】:

您正在为 64 位 (x64) 进行编译,而 PNaCl 不支持,或者某些标头中的一些 #error 您没有向我们显示(因为您剪掉了大部分错误得到)正在告诉你。

不过,为什么__int64 会触发错误,我不知道,因为那是MSVC builtin type。此外,使用<cinttypes>std::int64_t(可选)或std::int_least64_t(始终在符合标准的实现中可用)。

【讨论】:

我已经更新了我的帖子,添加了“错误列表”截图。 @Signum:尝试获取错误的文本格式(很可能在构建日志中)。我无法辨认你屏幕截图中的一半字母。 你用的是什么编译器?您不能使用 Visual Studio 自己的编译器,您必须使用 SDK 附带的 pnacl-clang++(但您可以从 Visual Studio UI 调用 pnacl-clang++)。请提供错误的文本版本以及编译器调用信息。

以上是关于PNaCl - 编译错误“仅支持 Win32 目标”的主要内容,如果未能解决你的问题,请参考以下文章

如何在 PNaCl 中等待 WebSocket 响应

Chrome 的 PNaCl 还活着么?

PNaCl 再见,WebAssembly 你好!

Chrome:再见 PNaCl,你好 WebAssembly

vysor不能用,黑屏中。。。。。怎么解决的么 ?

pypy 在浏览器中?