为什么这个用于在c++ 11和TR1之间切换的预处理器宏不能工作?
Why does this preprocessor macro for toggling between C++11 and TR1 not work?
例如,我正在尝试:
#if __cplusplus >= 201103L
#include <unordered_set>
typedef std::unordered_set<std::string> UnorderedStringSet;
#else
#include <tr1/unordered_set>
typedef std::tr1::unordered_set<std::string> UnorderedStringSet;
#endif
它在c++ tr1 CentOS 5.6上工作正常,在c++ 11支持的Xcode (mavericks)中工作正常,但在c++ 11 mac OS (mavericks)的命令行上似乎失败了。
edit要清楚,这在c++ 11编译器上是失败的。或者应该是c++ 11编译器。也许这就是问题所在。
错误是:
MyFile.cpp fatal error: 'tr1/unordered_set' file not found
显然,它没有正确地评估#if __cplusplus>= 201103L。
编译器参数:g++ -I. -I/snipped - -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /Users/xxxxx/src/MyFile.cpp -fno-common -DPIC -o src/.libs/MyFile.o
编译器版本:
$ g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.2.0
Thread model: posix
怎么了?也许有更好的办法?
您实际上不是在用c++ 11编译。您需要将-std=c++11
传递给g++
相关文章:
- 错误:无效的预处理指令 #i 的意思是 #if?
- C++预处理会生成变量成员、资源库和映射
- 使用预处理指令检查是否包含标头?
- 预处理的 C/C++ 文件是否特定于计算机?
- 使用 GCC 对 C 文件进行部分预处理(不删除 "define" 指令)
- 在 CPLEX 中求解线性规划,无需剪切和预处理
- CPP -D 选项,用于预处理 Fortran 代码
- 错误:粘贴"tmp_UINT"和"+"未提供有效的预处理令牌
- 任务计划程序库的预处理不起作用 - 多定义错误
- Eclipse 问题 - 编译期间不考虑 .c 和 .cpp 文件中定义的预处理
- 使用python预处理后,C++(opencv)中的垫子类型数据与image_to_array相同
- Howo 使用 cl 预处理为 masm 组装生成一个单独的文件
- 我有一个预处理的 C/C++ 源文件 (cacti.i).如何从这个 .i 文件生成可执行二进制文件,以便我可以像 ./
- 如何使用Visual Studio C/C++编译器(cl.exe)来预处理我的objective-C代码
- 是具有预处理前分支实现的结构违反ODR
- 与不完整的Cholesky预处理的共轭梯度返回特征库的意外错误
- Visual Studio C - 无法输出预处理文件
- 在海湾合作委员会中加快宏观预处理的任何方法
- Xmllint未设置,而在路径中找不到XMLLINT;跳过XML预处理
- 当头文件被预处理时是否有一个预处理器选项显示?