C++ 编译错误,包括 X11/X.h X11/Xlib.h
Posted
技术标签:
【中文标题】C++ 编译错误,包括 X11/X.h X11/Xlib.h【英文标题】:C++ compiling error including X11/X.h X11/Xlib.h 【发布时间】:2014-03-18 10:10:33 【问题描述】:我目前正在将在 MS VS2005 中开发的 c++ 应用程序移植到 linux 上,不幸的是这是我第一次这样做。我们正在使用 Qt 4.6、Opencascade 6.5.1 和 Qwt 6.0.1。 大多数代码编译得很好,但有一次我们试图使用 X 来确定客户端屏幕大小,一旦我尝试包含 X 库,我就会遇到大量错误。类头包含以下几行:
#ifdef WNT
#include <windows.h>
#else
#include <X11/X.h>
#include <X11/Xlib.h>
#endif //WNT
当我只有 #include <X11/X.h>
行时,我收到以下错误:
In file included from v0000/plot_curve.h:7,
from v0000/utility.h:9,
from v0000/settings.h:16,
from v0000/dialog.cpp:10:
../../../qwt-6.0.1/include/qwt_symbol.h:35: error: expected identifier before numeric constant
../../../qwt-6.0.1/include/qwt_symbol.h:35: error: expected `' before numeric constant
... <many more of these in this file>
In file included from v0000/plot_curve.h:7,
from v0000/utility.h:9,
from v0000/settings.h:16,
from v0000/dialog.cpp:10:
../../../qwt-6.0.1/include/qwt_symbol.h:10:1: unterminated #ifndef
In file included from v0000/utility.h:9,
from v0000/settings.h:16,
from v0000/dialog.cpp:10:
v0000/plot_curve.h:1:1: unterminated #ifndef
In file included from v0000/settings.h:16,
from v0000/dialog.cpp:10:
v0000/utility.h:1:1: unterminated #ifndef
In file included from v0000/dialog.cpp:10:
v0000/settings.h:1:1: unterminated #ifndef
并且仅使用 #include <X11/Xlib.h>
行:
In file included from ../../../../lib/inc/gce_MakeDir.hxx:20,
from v0000/bounding_box.cpp:17:
../../../../lib/inc/gce_Root.hxx:49: error: expected unqualified-id before ')' token
In file included from ../../../../lib/inc/gce_Root.hxx:71,
from ../../../../lib/inc/gce_MakeDir.hxx:20,
from v0000/bounding_box.cpp:17:
../../../../lib/inc/gce_Root.lxx:11: error: expected unqualified-id before "int"
我们需要 X 的代码目前已停用,因此如果没有这两个包含,一切都可以正常编译。
我似乎真的无法找到问题的根源。 X 包含路径是正确的,qt 和 occ 的示例应用程序可以工作(所以我猜他们正在使用 X 并且安装应该没问题)并且我找不到包含保护的错误。
//编辑 根据要求,这里是发生错误的文件的源代码:
qwt_symbol.h: (qwt)
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#ifndef QWT_SYMBOL_H
#define QWT_SYMBOL_H
#include "qwt_global.h"
#include <QPolygonF>
class QPainter;
class QRect;
class QSize;
class QBrush;
class QPen;
class QColor;
class QPointF;
//! A class for drawing symbols
class QWT_EXPORT QwtSymbol
public:
/*!
Symbol Style
\sa setStyle(), style()
*/
enum Style
//! No Style. The symbol cannot be drawn.
NoSymbol = -1,
//! Ellipse or circle
Ellipse,
//! Rectangle
Rect,
//! Diamond
Diamond,
//! Triangle pointing upwards
Triangle,
//! Triangle pointing downwards
DTriangle,
//! Triangle pointing upwards
UTriangle,
//! Triangle pointing left
LTriangle,
//! Triangle pointing right
RTriangle,
//! Cross (+)
Cross,
//! Diagonal cross (X)
XCross,
//! Horizontal line
HLine,
//! Vertical line
VLine,
//! X combined with +
Star1,
//! Six-pointed star
Star2,
//! Hexagon
Hexagon,
/*!
Styles >= QwtSymbol::UserSymbol are reserved for derived
classes of QwtSymbol that overload drawSymbols() with
additional application specific symbol types.
*/
UserStyle = 1000
;
public:
QwtSymbol( Style = NoSymbol );
QwtSymbol( Style, const QBrush &, const QPen &, const QSize & );
QwtSymbol( const QwtSymbol & );
virtual ~QwtSymbol();
QwtSymbol &operator=( const QwtSymbol & );
bool operator==( const QwtSymbol & ) const;
bool operator!=( const QwtSymbol & ) const;
void setSize( const QSize & );
void setSize( int width, int height = -1 );
const QSize& size() const;
virtual void setColor( const QColor & );
void setBrush( const QBrush& b );
const QBrush& brush() const;
void setPen( const QPen & );
const QPen& pen() const;
void setStyle( Style );
Style style() const;
void drawSymbol( QPainter *, const QPointF & ) const;
void drawSymbols( QPainter *, const QPolygonF & ) const;
virtual QSize boundingSize() const;
protected:
virtual void drawSymbols( QPainter *,
const QPointF *, int numPoints ) const;
private:
class PrivateData;
PrivateData *d_data;
;
/*!
\brief Draw the symbol at a specified position
\param painter Painter
\param pos Position of the symbol in screen coordinates
*/
inline void QwtSymbol::drawSymbol(
QPainter *painter, const QPointF &pos ) const
drawSymbols( painter, &pos, 1 );
/*!
\brief Draw symbols at the specified points
\param painter Painter
\param points Positions of the symbols in screen coordinates
*/
inline void QwtSymbol::drawSymbols(
QPainter *painter, const QPolygonF &points ) const
drawSymbols( painter, points.data(), points.size() );
#endif
gce_root.hxx: (opencascade)
// This file is generated by WOK (CPPExt).
// Please do not edit this file; modify original file instead.
// The copyright and license terms as defined for the original file apply to
// this header file considered to be the "object code" form of the original source.
#ifndef _gce_Root_HeaderFile
#define _gce_Root_HeaderFile
#ifndef _Standard_HeaderFile
#include <Standard.hxx>
#endif
#ifndef _Standard_Macro_HeaderFile
#include <Standard_Macro.hxx>
#endif
#ifndef _gce_ErrorType_HeaderFile
#include <gce_ErrorType.hxx>
#endif
#ifndef _Standard_Boolean_HeaderFile
#include <Standard_Boolean.hxx>
#endif
//! This class implements the common services for <br>
//! all classes of gce which report error. <br>
class gce_Root
public:
void* operator new(size_t,void* anAddress)
return anAddress;
void* operator new(size_t size)
return Standard::Allocate(size);
void operator delete(void *anAddress)
if (anAddress) Standard::Free((Standard_Address&)anAddress);
//! Returns true if the construction is successful. <br>
Standard_Boolean IsDone() const;
//! Returns the status of the construction: <br>
//! - gce_Done, if the construction is successful, or <br>
//! - another value of the gce_ErrorType enumeration <br>
//! indicating why the construction failed. <br>
gce_ErrorType Status() const;
protected:
gce_ErrorType TheError;
private:
;
#include <gce_Root.lxx>
// other Inline functions and methods (like "C++: function call" methods)
#endif
gce_root.lxx: (opencascade)
// File: gce_Root.cxx
// Created: Tue Sep 29 12:34:39 1992
// Author: Remi GILET
// <reg@sdsun2>
inline Standard_Boolean gce_Root::IsDone () const
return TheError == gce_Done;
inline gce_ErrorType gce_Root::Status() const
return TheError;
【问题讨论】:
我忘了说,目标系统是RHEL5。 你说你需要包含 X,你说当你这样做时,你会得到错误,但是你只提供了当你忽略包含它的标题时得到的错误......你不是显示您需要帮助的错误。 对不起我的英语。没有这两个包括代码编译。第一个错误块在我包含 X.h 时发生,第二个错误块在我包含 Xlib.h 时发生。我编辑我的帖子以澄清 在这种情况下,假设您第二次表示您已经包含了这两个标题......您需要显示错误抱怨的源代码行。由此,有人可能会建议您需要包含哪些额外的标题。 也许你可以告诉我们qwt_symbol.h
的第35行?我的猜测是其他一些邪恶的头文件定义了一个与该头文件中的东西同名的宏;但是没有看到代码,我只能猜测。
【参考方案1】:
包含以下内容:
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
我需要取消一些定义:
#undef Bool
#undef CursorShape
#undef Expose
#undef KeyPress
#undef KeyRelease
#undef FocusIn
#undef FocusOut
#undef FontChange
#undef None
#undef Status
#undef Unsorted
当然,在您的 .pro 文件中添加 LIBS += -lX11
,您就可以开始了!
【讨论】:
这是真正的答案。先生,您正在为人类做善事。【参考方案2】:它不能直接帮助您解决包含问题,但 QT 有一个用于确定客户端屏幕大小的类,称为 QDesktopWidget。所以你可以这样做:
QDesktopWidget *desktop = QApplication::desktop();
QRect geometry = desktop->availableGeometry();
或类的其他功能之一。它允许您从多个屏幕中进行选择并访问小部件所在的屏幕。
【讨论】:
【参考方案3】:您是否检查过以确保 Qt 没有定义 X11 所需的类型,例如 Bool?
查看Compiler does not see QX11Info,因为它涵盖了将 X11 与 Qt 结合时的常见问题。
您可能需要取消定义的不仅仅是 Bool。
【讨论】:
以上是关于C++ 编译错误,包括 X11/X.h X11/Xlib.h的主要内容,如果未能解决你的问题,请参考以下文章
libcvd - 编译 C++ 时对“x ...”的未定义引用
升级到 Xcode 11.x 后出现 UISegmentedControl 错误
iOS 14 解决方法中的 SceneKit Metal 着色器编译性能错误