开始使用 clang 3.6.0 和 Visual Studio 2013;如何解决"unknown argument: -ftemplate-depth"编译器错误?
Started using clang 3.6.0 with Visual Studio 2013; how do I solve my "unknown argument: -ftemplate-depth" compiler error?
我以前从未使用过clang,我认为现在是熟悉它的最佳时机。我安装了最新的Windows快照构建,它与Visual Studio集成在一起。
为了测试它,我开始做Project Euler问题。这是我用来解决问题1的代码:
#include <iostream>
template <unsigned int m, unsigned int n>
struct Mult
{
enum { Value = 0 };
};
template <>
struct Mult < 0, 0 >
{
enum { Value = 1 };
};
template <unsigned int m>
struct Mult < m, 0 >
{
enum { Value = 1 };
};
template <unsigned int n>
struct Mult < 0, n >
{
enum { Value = 1 };
};
template < unsigned int n >
struct EulerOne
{
enum { Value = (n * Mult<n % 3, n % 5>::Value) + EulerOne<n-1>::Value };
};
template <>
struct EulerOne < 0 >
{
enum { Value = 0 };
};
using namespace std;
int main(void)
{
cout << "Sum: " << EulerOne<999>::Value << endl;
return 0;
}
不一定是最好的代码,但仍然有效。我遇到的问题是模板初始化。微软的C++编译器被锁定在500的递归限制下,无法更改。clang应该有-fmplate depth=NNN选项。因此,我将-ftemplate-depth=1024
添加到项目的"附加选项"设置中。
我在编译时遇到的错误不是代码错误,而是编译器特定的错误:
1>clang-cl.exe : error : unknown argument: '-ftemplate-depth=1024'
我检查了一下,以确保我没有下载一些奇怪的、实验性的构建。我甚至做了以下事情:
> type "C:Program Files (x86)LLVMbinclang-cl.exe" | find "template-depth"
use -ftemplate-depth=N to increase recursive template instantiation depth
ftemplate-depth-
ftemplate-depth=
ftemplate-depth
-ftemplate-depth
我尝试使用-Xclang "-ftemplate-depth=1024"
,但最终出现了1>CL : error : unknown argument: '-ftemplate-depth=1024'
编译错误。
添加-v
选项后,这是它告诉我要运行的命令:
"C:\Program Files (x86)\LLVM\msbuild-bin\CL.exe" -cc1 -triple i686-pc-windows-msvc -emit-obj -disable-free -main-file-name p1.cpp -mrelocation-model static -mdisable-fp-elim -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases -target-cpu pentium4 -D_MT -D_DLL --dependent-lib=msvcrt --dependent-lib=oldnames -fexceptions -fcxx-exceptions -fdiagnostics-format msvc -v -gline-tables-only -dwarf-column-info -coverage-file "C:\Users\jsmith\documents\visual studio 2013\Projects\ProjectEulerCpp\P1\LLVM\p1.obj" -resource-dir "C:\Program Files (x86)\LLVM\msbuild-bin\..\lib\clang\3.6.0" -internal-isystem "C:\Program Files (x86)\LLVM\msbuild-bin\..\lib\clang\3.6.0\include" -internal-isystem "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include" -internal-isystem "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include" -internal-isystem "C:\Program Files (x86)\Windows Kits\8.1\Include\um" -internal-isystem "C:\Program Files (x86)\Windows Kits\8.1\Include\shared" -internal-isystem "C:\Program Files (x86)\Windows Kits\8.1\Include\winrt" -O2 -Wall -Wno-error -std=c++11 -fdeprecated-macro -fdebug-compilation-dir "C:\Users\jsmith\documents\visual studio 2013\Projects\ProjectEulerCpp\P1" -ferror-limit 19 -fmessage-length 0 -mstackrealign -fms-extensions -fms-compatibility -fms-compatibility-version=18.0 -fdelayed-template-parsing -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -ftemplate-depth=1024 -o "LLVM\p1.obj" -x c++ p1.cpp
无论我如何分割,我都无法使用此选项。有人有什么建议吗?
似乎是
clang-cl -Xclang -ftemplate-depth -Xclang 1024 test.cpp
我是怎么得到的:
gcc风格的驱动程序clang++
可以很好地接受-ftemplate-depth=1024
,因此我们可以查看它在指定该选项时生成的命令行:
C:LLVMbin>clang++ -v -ftemplate-depth=1024 -c test.cpp
clang version 3.5.0 (217039)
Target: i686-pc-windows-gnu
Thread model: posix
"C:LLVMbinclang++.exe" -cc1 -triple i686-pc-windows-gnu -emit-obj -mrelax-al
l -disable-free -main-file-name test.cpp -mrelocation-model static -mdisable-fp-
elim -fmath-errno -masm-verbose -mconstructor-aliases -target-cpu pentium4 -v -d
warf-column-info -coverage-file "C:\LLVM\bin\test.o" -resource-dir "C:\LLVM
bin\..\lib\clang\3.5.0" -fdeprecated-macro -fdebug-compilation-dir "C:\LLV
M\bin" -ftemplate-depth 1024 -ferror-limit 19 -fmessage-length 80 -mstackrealig
n -fno-use-cxa-atexit -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnos
tics-show-option -fcolor-diagnostics -o test.o -x c++ test.cpp
关键是,该选项作为两个命令行参数传递,-ftemplate-depth
后跟1024
。因此将其应用于CCD_ 10得到CCD_。
- 运行同一解决方案的另一个项目的项目
- Project Euler问题4的错误解决方案
- Ardunio UNO解决了多个重叠的定时器循环
- "unknown ca"自生成的 CA、证书和客户端/服务器
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- 两个文件使用彼此的功能-如何解决
- 计算每个节点的树高,帮助我解释这个代码解决方案
- 如何解决"invalid conversion from 'char' to 'const char*'"
- 在java中解决这段代码时面临循环中的问题
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 难以理解某些人解决IOI问题的源代码
- visual c++,如何获取解决方案目录中的代码
- 如何解决错误:SCIP C++中的 SCIP 阶段无效 <10>
- 节俭并发:未解决的外部问题
- IpOpt拒绝解决不受约束的问题
- 如何解决这个超硬恒星的创造问题
- 循环无限运行C++解决骑士之旅问题
- 有没有办法在远程设备上打开和编辑visual Studio 2017解决方案
- C++Matching Brackets 2解决方案不起作用
- 开始使用 clang 3.6.0 和 Visual Studio 2013;如何解决"unknown argument: -ftemplate-depth"编译器错误?