【问题标题】:newer gcc gives illegal syntax error in a header file较新的 gcc 在头文件中给出非法语法错误
【发布时间】:2013-08-05 13:23:52
【问题描述】:

我已经按照安装说明安装了mimetic 库。 以下主文件使用gcc-c++ 4.1.2 编译没有问题, 但是当我升级到gcc-c++ 4.4.7 时出现错误。

模拟.cpp:

#include <iostream>
#include <mimetic.h>

using namespace std;
using namespace mimetic;

int main()
{
    MimeEntity me;          
    return 0;
}

错误

In file included from /usr/local/include/mimetic/rfc822/header.h:18,
                 from /usr/local/include/mimetic/header.h:11,
                 from /usr/local/include/mimetic/mimetic.h:18,
                 from mimetic.cpp:2:
/usr/local/include/mimetic/rfc822/messageid.h:29: error: expected ‘)’ before ‘thread_id’

头文件: rfc822/messageid.h

#ifndef _MIMETIC_MESSAGEID_H_
#define _MIMETIC_MESSAGEID_H_
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#include <string>
#include <mimetic/libconfig.h>
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#include <mimetic/utils.h>
#include <mimetic/os/utils.h>
#include <mimetic/rfc822/fieldvalue.h>

namespace mimetic
{
/// Message-ID field value 
/// On Win32 Winsock library must be initialized before using this class.
struct MessageId: public FieldValue
{
    MessageId(uint32_t thread_id = 0 ); // <------ line 29
    MessageId(const std::string&);
    std::string str() const;
    void set(const std::string&);
protected:
    FieldValue* clone() const;
private:
    static unsigned int ms_sequence_number;
    std::string m_msgid;
};
}
#endif

gcc 是否有一些兼容性开关?

【问题讨论】:

  • 我怀疑你的 HAVE_STDINT_HHAVE_INTTYPES_H 是“错误的”,所以你没有得到 uint32_t
  • @Mats Petersson 如何检查这些是否正确?
  • 尝试在HAVE_STDINT_H 中添加下一个#error this should give an error,开始。如果您没有收到错误,则未设置 HAVE_STDINT_H - 我很确定它应该是 [虽然从技术上讲,因为它是 C++ 代码,它确实应该使用 cstdint - 但我怀疑它是否会产生区别]。
  • 您可以尝试将 -DHAVE_STDINT_H 添加到 gcc 的参数中,看看它是否有效。确保设置标志的正确方法取决于您的构建系统。
  • 另外,如果您的系统缺少 stdint.h,您需要有提供适当typedefs 的替换代码,或者根据@定义您自己的抽象类型987654336@ 类型(如果存在)或系统特定类型(如果不存在)。就cstdint 而言,我使用过提供stdint.h 但不提供cstdint 的C++ 编译器......

标签: c++ gcc


【解决方案1】:

因此,问题原来是系统配置不佳,导致未配置 HAVE_STDINT_H,因此未定义 uint32_t,并发生错误。

【讨论】:

    猜你喜欢
    • 2013-02-10
    • 2020-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-06
    • 2011-03-29
    • 1970-01-01
    相关资源
    最近更新 更多