代码之家  ›  专栏  ›  技术社区  ›  Chris Tonkinson

从yaml cpp传出编译器错误

  •  0
  • Chris Tonkinson  · 技术社区  · 14 年前

    我试图将yamlcpp集成到一个项目中,但是我看到GCC中出现了一些意想不到的错误。例如:

    g++ -c -ggdb3 -ansi -Wall -Werror -pedantic-errors src/commands-tz.cpp -o obj/commands-tz.o
    In file included from /usr/local/include/yaml-cpp/conversion.h:9,
                     from /usr/local/include/yaml-cpp/node.h:8,
                     from /usr/local/include/yaml-cpp/parser.h:8,
                     from /usr/local/include/yaml-cpp/yaml.h:8,
                     from src/note.h:26,
                     from src/commands-tz.cpp:297:
    /usr/local/include/yaml-cpp/traits.h:26: error: expected identifier before ‘(’ token
    /usr/local/include/yaml-cpp/traits.h:26: error: expected ‘)’ before numeric constant
    /usr/local/include/yaml-cpp/traits.h:26: error: expected ‘>’ before numeric constant
    /usr/local/include/yaml-cpp/traits.h:26: error: expected unqualified-id before ‘)’ token
    /usr/local/include/yaml-cpp/traits.h:31: error: expected identifier before ‘(’ token
    /usr/local/include/yaml-cpp/traits.h:31: error: expected ‘)’ before numeric constant
    /usr/local/include/yaml-cpp/traits.h:31: error: expected ‘>’ before numeric constant
    /usr/local/include/yaml-cpp/traits.h:31: error: expected unqualified-id before ‘)’ token
    /usr/local/include/yaml-cpp/traits.h:34: error: expected identifier before ‘(’ token
    /usr/local/include/yaml-cpp/traits.h:34: error: expected ‘)’ before numeric constant
    /usr/local/include/yaml-cpp/traits.h:34: error: expected ‘>’ before numeric constant
    /usr/local/include/yaml-cpp/traits.h:34: error: expected unqualified-id before ‘)’ token
    /usr/local/include/yaml-cpp/traits.h:37: error: expected identifier before ‘(’ token
    /usr/local/include/yaml-cpp/traits.h:37: error: expected ‘)’ before numeric constant
    /usr/local/include/yaml-cpp/traits.h:37: error: expected ‘>’ before numeric constant
    /usr/local/include/yaml-cpp/traits.h:37: error: expected unqualified-id before ‘)’ token
    /usr/local/include/yaml-cpp/traits.h:42: error: expected identifier before ‘(’ token
    /usr/local/include/yaml-cpp/traits.h:42: error: expected ‘)’ before numeric constant
    /usr/local/include/yaml-cpp/traits.h:42: error: expected ‘>’ before numeric constant
    /usr/local/include/yaml-cpp/traits.h:42: error: expected unqualified-id before ‘)’ token
    /usr/local/include/yaml-cpp/traits.h:45: error: expected identifier before ‘(’ token
    /usr/local/include/yaml-cpp/traits.h:45: error: expected ‘)’ before numeric constant
    /usr/local/include/yaml-cpp/traits.h:45: error: expected ‘>’ before numeric constant
    /usr/local/include/yaml-cpp/traits.h:45: error: expected unqualified-id before ‘)’ token
    

    In file included from /usr/local/include/yaml-cpp/nodeimpl.h:8,
                     from /usr/local/include/yaml-cpp/node.h:139,
                     from /usr/local/include/yaml-cpp/parser.h:8,
                     from /usr/local/include/yaml-cpp/yaml.h:8,
                     from src/note.h:26,
                     from src/commands-tz.cpp:297:
    /usr/local/include/yaml-cpp/nodeutil.h:9: error: expected nested-name-specifier before ‘(’ token
    /usr/local/include/yaml-cpp/nodeutil.h:9: error: expected ‘)’ before numeric constant
    /usr/local/include/yaml-cpp/nodeutil.h:9: error: expected ‘>’ before numeric constant
    /usr/local/include/yaml-cpp/nodeutil.h:9: error: expected unqualified-id before ‘)’ token
    /usr/local/include/yaml-cpp/nodeutil.h:14: error: expected nested-name-specifier before ‘(’ token
    /usr/local/include/yaml-cpp/nodeutil.h:14: error: expected ‘)’ before numeric constant
    /usr/local/include/yaml-cpp/nodeutil.h:14: error: expected ‘>’ before numeric constant
    /usr/local/include/yaml-cpp/nodeutil.h:14: error: expected unqualified-id before ‘)’ token
    /usr/local/include/yaml-cpp/nodeutil.h:19: error: expected nested-name-specifier before ‘(’ token
    /usr/local/include/yaml-cpp/nodeutil.h:19: error: expected ‘)’ before numeric constant
    /usr/local/include/yaml-cpp/nodeutil.h:19: error: expected ‘>’ before numeric constant
    /usr/local/include/yaml-cpp/nodeutil.h:19: error: expected unqualified-id before ‘)’ token
    /usr/local/include/yaml-cpp/nodeutil.h:24: error: ‘is_index_type_with_check’ is not a template
    /usr/local/include/yaml-cpp/nodeutil.h:24: error: explicit specialization of non-template ‘YAML::is_index_type_with_check’
    

    更新

    traits.h文件包含以下内容:

    namespace YAML
    {
            template <typename>
            struct is_numeric { enum { value = false }; };
    
            template <> struct is_numeric <char> { enum { value = true }; };
            template <> struct is_numeric <unsigned char> { enum { value = true }; };
            template <> struct is_numeric <int> { enum { value = true }; };
            template <> struct is_numeric <unsigned int> { enum { value = true }; };
            template <> struct is_numeric <long int> { enum { value = true }; };
            template <> struct is_numeric <unsigned long int> { enum { value = true }; };
            template <> struct is_numeric <short int> { enum { value = true }; };
            template <> struct is_numeric <unsigned short int> { enum { value = true }; };
            template <> struct is_numeric <long long> { enum { value = true }; };
            template <> struct is_numeric <unsigned long long> { enum { value = true }; };
            template <> struct is_numeric <float> { enum { value = true }; };
            template <> struct is_numeric <double> { enum { value = true }; };
            template <> struct is_numeric <long double> { enum { value = true }; };
    
            template <bool, class T = void>
            struct enable_if_c {
              typedef T type;
            };
    
            template <class T>
            struct enable_if_c<false, T> {};
    
            template <class Cond, class T = void>
            struct enable_if : public enable_if_c<Cond::value, T> {};
    
            template <bool, class T = void>
            struct disable_if_c {
              typedef T type;
            };
    
            template <class T>
            struct disable_if_c<true, T> {};
    
            template <class Cond, class T = void>
            struct disable_if : public disable_if_c<Cond::value, T> {};
    }
    

    namespace YAML
    {
            template <typename T, typename U>
            struct is_same_type {
                    enum { value = false };
            };
    
            template <typename T>
            struct is_same_type<T, T> {
                    enum { value = true };
            };
    
            template <typename T, bool check>
            struct is_index_type_with_check {
                    enum { value = false };
            };
    
            template <> struct is_index_type_with_check<std::size_t, false> { enum { value = true }; };
    
    #define MAKE_INDEX_TYPE(Type) \
            template <> struct is_index_type_with_check<Type, is_same_type<Type, std::size_t>::value> { enum { value = true }; }
    
            MAKE_INDEX_TYPE(int);
            MAKE_INDEX_TYPE(unsigned);
            MAKE_INDEX_TYPE(short);
            MAKE_INDEX_TYPE(unsigned short);
            MAKE_INDEX_TYPE(long);
            MAKE_INDEX_TYPE(unsigned long);
    
    #undef MAKE_INDEX_TYPE
    
            template <typename T>
            struct is_index_type: public is_index_type_with_check<T, false> {};
    
            // messing around with template stuff to get the right overload for operator [] for a sequence
            template <typename T, bool b>
            struct _FindFromNodeAtIndex {
                    const Node *pRet;
                    _FindFromNodeAtIndex(const Node&, const T&): pRet(0) {}
            };
    
            template <typename T>
            struct _FindFromNodeAtIndex<T, true> {
                    const Node *pRet;
                    _FindFromNodeAtIndex(const Node& node, const T& key): pRet(node.FindAtIndex(static_cast<std::size_t>(key))) {}
            };
    
            template <typename T>
            inline const Node *FindFromNodeAtIndex(const Node& node, const T& key) {
                    return _FindFromNodeAtIndex<T, is_index_type<T>::value>(node, key).pRet;
            }
    }
    
    2 回复  |  直到 14 年前
        1
  •  1
  •   Gianni    14 年前

    你好像在地狱里。您发布的traits.h文件不包含“(”,但gcc会抱怨“(”之前的内容。这可能意味着您正在包含与此文件中的某个宏同名的宏。尝试对项目中的include重新排序,看看是否有什么不同。

        2
  •  0
  •   Robert Boehne    14 年前

    编译程序