无法用gcc 4.6.1编译代码
Cannot compile code with gcc 4.6.1
下面的代码在VS2010中可以很好地编译,但不希望在gcc 4.6.1中编译。:
#ifndef IS_CHAR_H_INCLUDED
#define IS_CHAR_H_INCLUDED
#include <type_traits>
template<class Int_T>
struct Is_Char_
{
enum {value = false};
};
template<>
struct Is_Char_<char>
{
enum {value = true};
};
template<>
struct Is_Char_<unsigned char>
{
enum {value = true};
};
template<>
struct Is_Char_<signed char>
{
enum {value = true};
};
template<class Int_T>
struct Is_Char : Is_Char_<typename std::remove_cv<Int_T>::type>
{
};
#endif // IS_CHAR_H_INCLUDED
#ifndef PROMOTE_H_INCLUDED
#define PROMOTE_H_INCLUDED
#include <type_traits>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/find.hpp>
#include <boost/mpl/next.hpp>
#include <boost/mpl/deref.hpp>
#include <boost/mpl/end.hpp>
//#include "Is_Char.h" doesn't have to be here this file is pasted above
/*Promotes Integer type to one up in size range*/
template<class Integer>
struct Promote
{
static_assert(std::is_integral<Integer>::value,"Non Integer type is not allowed.");
/*Check correct type - depending on Integer being signed or unsigned*/
typedef typename std::conditional<std::is_signed<Integer>::value,
boost::mpl::vector<signed char,short,int,long,long long>,
boost::mpl::vector<unsigned char,unsigned short,unsigned int,long,long long>
>::type types;
/*
Find this type from the list above - substituting Integer for signed or unsigned char iff Integer is of type char
*/
typedef typename boost::mpl::find<types,
typename std::conditional<Is_Char<Integer>::value,
typename std::conditional<std::is_signed<Integer>::value,signed char,unsigned char>::type, Integer>::type>::type this_type;
/*If Integer is int and if size of it is == to long promote int to long long (iterate to next element twice)*/
typedef typename boost::mpl::eval_if<boost::mpl::bool_<((std::is_same<Integer,int>::value || std::is_same<Integer,unsigned int>::value)
&& (sizeof(int) == sizeof(long)))>,
boost::mpl::next<typename boost::mpl::next<this_type>::type>,
boost::mpl::next<this_type>
>::type next_type;
/*Check if iterator points within range or if one pass end which means that Integer was u/long long*/
typedef typename std::conditional<std::is_same<typename boost::mpl::end<types>::type,next_type>::value,Integer,typename boost::mpl::deref<next_type>::type>::type type;
};
#endif // PROMOTE_H_INCLUDED
我的猜测是您在编译时没有指定
--std=c++0x
,因此std::is_integral<>
等c++ 11特性不可用。当我使用该选项时,你的代码为我编译。
UPDATE:现在您已经显示了编译器输出,问题是您已经启用了几乎所有可能的警告,并且还将-Wpedantic-errors
设置为将其中一些视为错误。许多这些警告都是由完全合理的代码触发的,大多数作者(包括Boost)不会花时间修复或解决所有这些问题。
你当然应该删除-Wpedantic-errors
,除非你有一个特殊的要求,任何代码都不应该使用特定于编译器的扩展;在这种情况下,您可能无法使用Boost。禁用一些不太有用的警告可能也是一个好主意—您无法修复Boost生成的警告,因此它们所做的只是使发现有关代码的真正警告变得更加困难。我通常的目标是使用-Wall -Wextra
进行简洁的编译。
真正的问题不在您的代码中。问题是您找不到编译器的错误消息。在你做任何事情之前先解决这个问题!
在终端内运行确切的g++
命令。你会看到错误。不要使用IDE
相关文章:
- 在Linux for Windows上编译C++代码时出错
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 在程序中编写脚本来编写和编译代码
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 在macos上编译代码的未解析符号
- 使用个人C++库编译代码时,与头文件一起使用时会中断
- 使用指针编译代码后,.cpp文件将变为随机字符
- VS Express 无法正确编译代码(?
- 如何在Ubuntu中使用Visual Studio代码编译C++代码
- 使用 Android NDK 使用 clang++ 编译C++代码时对"_Unwind_Resume"的未定义引用
- 无法使用两个包装不同下一层的ssl_stream编译代码
- 编译代码时"[Warning] extra tokens at end of"
- 无法编译代码,因为它已在 C++11 中弃用
- 如何在 Azure 应用服务中使用 cl.exe 编译 C++ 代码并生成可执行文件
- 如何调试编译 c++ 代码的 bazel?
- 为什么在使用转换构造函数编译代码时需要 const 复制构造函数?
- 编译 C++ 代码后尺寸较大
- 使用用 C++ 和 DDS 编写的 CMAKE 编译代码
- 编译代码时如何不制作二进制文件?
- 如何使用所有其他文件信息来编译代码,例如HAAR级联训练的权重的XML文件