[英]C++ compiling error including X11/X.h X11/Xlib.h
I am currently porting a c++ application developed in MS VS2005 to linux and unfortunately this is the first time I am doing this. 我目前正在将用MS VS2005开发的c ++应用程序移植到linux,不幸的是,这是我第一次这样做。 We are using Qt 4.6, Opencascade 6.5.1 and Qwt 6.0.1.
我们正在使用Qt 4.6, Opencascade 6.5.1和Qwt 6.0.1。 Most of the code compiles just fine but at one point we are trying to use X to determine the client screen size and as soon as I am trying to include X libraries i get a ton of errors.
大多数代码都可以正常编译,但有一次我们试图使用X来确定客户端屏幕的大小,而一旦我试图包含X库,我就会遇到很多错误。 The class header contains the following lines:
类头包含以下几行:
#ifdef WNT
#include <windows.h>
#else
#include <X11/X.h>
#include <X11/Xlib.h>
#endif //WNT
When I have only the #include <X11/Xh>
line I get the following errors: 当我只有
#include <X11/Xh>
行时,出现以下错误:
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
and with the #include <X11/Xlib.h>
line only: 并且仅使用
#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"
The code we need X for is currently deactivated so without the two includes, everything compiles just fine. 目前,我们需要X的代码已被停用,因此,如果没有这两个包含,一切编译就可以了。
I really can't seem to track down the root of the problem. 我真的似乎无法找到问题的根源。 The X include path is correct, sample applications of qt and occ work (so I guess they are using X and the installation should be ok) and I could not find an error with include guards.
X包含路径正确,qt和occ的示例应用程序正常工作(因此我想它们正在使用X,并且安装应该可以),并且找不到包含保护的错误。
//edit as requested, here is the source code of the files in which the errors occur: //按要求编辑 ,这是发生错误的文件的源代码:
qwt_symbol.h: (qwt) 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) 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) 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;
}
It does not help your include problem directly, but QT has a class for determining client screen size, called QDesktopWidget . 它不能直接帮助您解决包含问题,但是QT有一个用于确定客户端屏幕尺寸的类,称为QDesktopWidget 。 So you could do something like that:
因此,您可以执行以下操作:
QDesktopWidget *desktop = QApplication::desktop();
QRect geometry = desktop->availableGeometry();
Or one of the other functions of the class. 或该类的其他功能之一。 It allows you to select from multiple screens and access the screen a widget is in.
它允许您从多个屏幕中选择并访问小部件所在的屏幕。
With the following includes: 包括以下内容:
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
I needed to undef a few definitions: 我需要取消一些定义:
#undef Bool
#undef CursorShape
#undef Expose
#undef KeyPress
#undef KeyRelease
#undef FocusIn
#undef FocusOut
#undef FontChange
#undef None
#undef Status
#undef Unsorted
Of course add LIBS += -lX11
in your .pro file, and you are good to go! 当然,在您的.pro文件中添加
LIBS += -lX11
,您一切顺利!
Have you checked to make sure that Qt is not defining types that X11 requires, such as Bool? 您是否检查过以确保Qt并未定义X11所需的类型,例如Bool?
Take a look at Compiler does not see QX11Info as this covers a common problem when including X11 with Qt. 看一看Compiler看不到QX11Info,因为在Xt中包含X11时,这涵盖了一个常见问题。
You may need to undef more than just Bool. 您可能不仅需要取消对Bool的定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.