从Qt文件中编译时间错误:预期的不合格id。

时间:2022-10-13 23:15:13

Porting my project from Qt4 to Qt5.1, I get this error from a Qt file:

将我的项目从Qt4移植到Qt5.1,我从Qt文件中得到这个错误:

C:\Qt\Qt5.1.1\5.1.1\mingw48_32\include\QtGui\qopenglversionfunctions.h:785: error: expected unqualified-id before ')' token
     void (QOPENGLF_APIENTRYP MemoryBarrier)(GLbitfield barriers);
                                           ^

This is the chain of defines:

这是定义的链:

#define QOPENGLF_APIENTRYP QOPENGLF_APIENTRY *
#define QOPENGLF_APIENTRY APIENTRY
#define APIENTRY WINAPI
#define WINAPI __stdcall

I noticed that the "MemoryBarrier" token is present in the libQt5OpenGLExtensionsd.a library. Should I include it, even if in the original Qt4 project nothing related to OpenGL was used?

我注意到在libQt5OpenGLExtensionsd中存在“MemoryBarrier”令牌。一个图书馆。我是否应该包括它,即使在最初的Qt4项目中没有使用OpenGL ?

Platform:
Windows 7
MinGW 4.8
Qt 4.8 --> Qt 5.1

平台:Windows 7 MinGW 4.8 Qt 4.8——> Qt 5.1。

4 个解决方案

#1


5  

I noticed that the "MemoryBarrier" token is present in the libQt5OpenGLExtensionsd.a library. Should I include it, even if in the original Qt4 project nothing related to OpenGL was used?

我注意到在libQt5OpenGLExtensionsd中存在“MemoryBarrier”令牌。一个图书馆。我是否应该包括它,即使在最初的Qt4项目中没有使用OpenGL ?

No, those are not related. OpenGLExtension is compiled after QtGui.

不,那些不是相关的。OpenGLExtension是在QtGui之后编译的。

What you are hitting unfortunately is that there is a MemoryBarrier() already defined on Windows, and hence there is a * for that and what qt is having. You can find the official Windows documentation for that:

不幸的是,在Windows上已经定义了一个MemoryBarrier(),因此它与qt之间存在冲突。你可以找到官方的Windows文档:

http://msdn.microsoft.com/en-us/library/windows/apps/ms684208(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/windows/apps/ms684208(v = vs.85). aspx

I have just discussed this with Gunnar, the QtGui maintainer, and I am planning to submit a change to Gerrit to address your issue.

我刚刚和Gunnar, QtGui维护人员讨论过这个问题,我打算提交一个变更到Gerrit来解决您的问题。

We had used something like this in our project a couple of years ago when we were writing thread-safe singletons based on QtCore:

几年前,我们在我们的项目中使用了类似的东西当我们基于QtCore编写线程安全的单件时:

#if defined __GNUC__ && __GNUC__ >= 4 && __GNUC_MINOR__ >= 4    
#define __MEMBARRIER __sync_synchronize();  
#elif defined _MSC_VER && defined _WIN64    
#define __MEMBARRIER MemoryBarrier();   
#else   
#define __MEMBARRIER
#endif

Qt may need to check ifdef MINGW/GCC/VERSION and undef the MemoryBarrier define.

Qt可能需要检查ifdef MINGW/GCC/版本和undef的MemoryBarrier定义。

EDIT: This was fixed about half a year ago. See the following Gerrit review and the corresponding bug report for details:

编辑:这是大约半年前修好的。详见以下Gerrit review和相应的bug报告:

https://codereview.qt-project.org/#change,68156

https://codereview.qt-project.org/的变化,68156年

and

https://bugreports.qt.io/browse/QTBUG-34080

https://bugreports.qt.io/browse/qtbug - 34080

So, update to Qt 5.2.0 and it will work. Failing that, you can try to backport it.

因此,更新到Qt 5.2.0,它将会起作用。如果不行,你可以试着把它背下来。

#2


7  

Besides the bug in MinGW 4.8.1 with uint64_t in io.h, there is also this one in QT 5.2.1 still. I came across this today when trying to compile QT 5.2.1 with MinGW 4.8.1, so I thought I would post my solution as well.

此外,在io中使用uint64_t,在MinGW 4.8.1中有bug。h,还有这个在QT 5.2.1中。我今天遇到这个问题时,试图用MinGW 4.8.1来编译QT 5.2.1,所以我想我也会发布我的解决方案。

I don't know what the official fix will be for QT, but for my needs I did it like this:

我不知道QT的官方解决方案是什么,但是为了我的需要,我这样做了:

in src/gui/opengl/qopengl.h line 49:

在src / gui / opengl / qopengl。h 49行:

// Windows always needs this to ensure that APIENTRY gets defined
#if defined(Q_OS_WIN)
# include <QtCore/qt_windows.h>
#endif

I just undefined the windows MemoryBarrier macro there:

我在这里没有定义windows MemoryBarrier宏:

// Windows always needs this to ensure that APIENTRY gets defined
#if defined(Q_OS_WIN)
# include <QtCore/qt_windows.h>
# undef MemoryBarrier
#endif

#3


1  

I run into the same problem. I could compile and run with just commenting out the problematic line:

我遇到了同样的问题。我可以用注释来编译和运行这条有问题的线:

// void (QOPENGLF_APIENTRYP MemoryBarrier)(GLbitfield barriers);

In file C:/Qt/Qt5.1.1/5.1.1/mingw48_32/include/QtGui/qopenglversionfunctions.h:785

在文件C:/ Qt / Qt5.1.1/5.1.1 / mingw48_32 / include / QtGui / qopenglversionfunctions.h:785

My application does not use any OpenGL stuff. Let's hope they fix it soon ;-)

我的申请不使用任何OpenGL的东西。希望他们能尽快修好它。

#4


1  

Since the accepted answer doesn't seem to help when one tries to build the QT library on it's own and Laszlo Pap claims that thie other solution is not a proper fix, I tried to find a way to fix it correctly. On Google I found a posting where it was said that MemoryBarrier is not implemented in MingW and there was a patch for it.

以来接受的答案似乎没有帮助,当一个人试图建立QT库在它自己的和Laszlo Pap声称这其他解决方案不是一个适当的修复,我试图找到一种方法来正确地解决它。在谷歌上我发现了一个帖子,据说MemoryBarrier MingW没有实现,有一个补丁。

So I tried to incorporate the fix into opengl.h and hope that this is the correct way as simply commenting out the lines may cause problems later on.

所以我试图修复合并到opengl。h和希望这是正确的方式简单地评论了线以后可能会引起麻烦。

#ifndef QT_NO_OPENGL

// Windows always needs this to ensure that APIENTRY gets defined
#if defined(Q_OS_WIN)

# include <QtCore/qt_windows.h>

#if defined(__MINGW32__) && defined(MemoryBarrier)
#undef MemoryBarrier

__CRT_INLINE void MemoryBarrier(void)
{
    long Barrier = 0;
    __asm__ __volatile__("xchgl %%eax,%0 "
        :"=r" (Barrier));
}
#endif

#endif

#1


5  

I noticed that the "MemoryBarrier" token is present in the libQt5OpenGLExtensionsd.a library. Should I include it, even if in the original Qt4 project nothing related to OpenGL was used?

我注意到在libQt5OpenGLExtensionsd中存在“MemoryBarrier”令牌。一个图书馆。我是否应该包括它,即使在最初的Qt4项目中没有使用OpenGL ?

No, those are not related. OpenGLExtension is compiled after QtGui.

不,那些不是相关的。OpenGLExtension是在QtGui之后编译的。

What you are hitting unfortunately is that there is a MemoryBarrier() already defined on Windows, and hence there is a * for that and what qt is having. You can find the official Windows documentation for that:

不幸的是,在Windows上已经定义了一个MemoryBarrier(),因此它与qt之间存在冲突。你可以找到官方的Windows文档:

http://msdn.microsoft.com/en-us/library/windows/apps/ms684208(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/windows/apps/ms684208(v = vs.85). aspx

I have just discussed this with Gunnar, the QtGui maintainer, and I am planning to submit a change to Gerrit to address your issue.

我刚刚和Gunnar, QtGui维护人员讨论过这个问题,我打算提交一个变更到Gerrit来解决您的问题。

We had used something like this in our project a couple of years ago when we were writing thread-safe singletons based on QtCore:

几年前,我们在我们的项目中使用了类似的东西当我们基于QtCore编写线程安全的单件时:

#if defined __GNUC__ && __GNUC__ >= 4 && __GNUC_MINOR__ >= 4    
#define __MEMBARRIER __sync_synchronize();  
#elif defined _MSC_VER && defined _WIN64    
#define __MEMBARRIER MemoryBarrier();   
#else   
#define __MEMBARRIER
#endif

Qt may need to check ifdef MINGW/GCC/VERSION and undef the MemoryBarrier define.

Qt可能需要检查ifdef MINGW/GCC/版本和undef的MemoryBarrier定义。

EDIT: This was fixed about half a year ago. See the following Gerrit review and the corresponding bug report for details:

编辑:这是大约半年前修好的。详见以下Gerrit review和相应的bug报告:

https://codereview.qt-project.org/#change,68156

https://codereview.qt-project.org/的变化,68156年

and

https://bugreports.qt.io/browse/QTBUG-34080

https://bugreports.qt.io/browse/qtbug - 34080

So, update to Qt 5.2.0 and it will work. Failing that, you can try to backport it.

因此,更新到Qt 5.2.0,它将会起作用。如果不行,你可以试着把它背下来。

#2


7  

Besides the bug in MinGW 4.8.1 with uint64_t in io.h, there is also this one in QT 5.2.1 still. I came across this today when trying to compile QT 5.2.1 with MinGW 4.8.1, so I thought I would post my solution as well.

此外,在io中使用uint64_t,在MinGW 4.8.1中有bug。h,还有这个在QT 5.2.1中。我今天遇到这个问题时,试图用MinGW 4.8.1来编译QT 5.2.1,所以我想我也会发布我的解决方案。

I don't know what the official fix will be for QT, but for my needs I did it like this:

我不知道QT的官方解决方案是什么,但是为了我的需要,我这样做了:

in src/gui/opengl/qopengl.h line 49:

在src / gui / opengl / qopengl。h 49行:

// Windows always needs this to ensure that APIENTRY gets defined
#if defined(Q_OS_WIN)
# include <QtCore/qt_windows.h>
#endif

I just undefined the windows MemoryBarrier macro there:

我在这里没有定义windows MemoryBarrier宏:

// Windows always needs this to ensure that APIENTRY gets defined
#if defined(Q_OS_WIN)
# include <QtCore/qt_windows.h>
# undef MemoryBarrier
#endif

#3


1  

I run into the same problem. I could compile and run with just commenting out the problematic line:

我遇到了同样的问题。我可以用注释来编译和运行这条有问题的线:

// void (QOPENGLF_APIENTRYP MemoryBarrier)(GLbitfield barriers);

In file C:/Qt/Qt5.1.1/5.1.1/mingw48_32/include/QtGui/qopenglversionfunctions.h:785

在文件C:/ Qt / Qt5.1.1/5.1.1 / mingw48_32 / include / QtGui / qopenglversionfunctions.h:785

My application does not use any OpenGL stuff. Let's hope they fix it soon ;-)

我的申请不使用任何OpenGL的东西。希望他们能尽快修好它。

#4


1  

Since the accepted answer doesn't seem to help when one tries to build the QT library on it's own and Laszlo Pap claims that thie other solution is not a proper fix, I tried to find a way to fix it correctly. On Google I found a posting where it was said that MemoryBarrier is not implemented in MingW and there was a patch for it.

以来接受的答案似乎没有帮助,当一个人试图建立QT库在它自己的和Laszlo Pap声称这其他解决方案不是一个适当的修复,我试图找到一种方法来正确地解决它。在谷歌上我发现了一个帖子,据说MemoryBarrier MingW没有实现,有一个补丁。

So I tried to incorporate the fix into opengl.h and hope that this is the correct way as simply commenting out the lines may cause problems later on.

所以我试图修复合并到opengl。h和希望这是正确的方式简单地评论了线以后可能会引起麻烦。

#ifndef QT_NO_OPENGL

// Windows always needs this to ensure that APIENTRY gets defined
#if defined(Q_OS_WIN)

# include <QtCore/qt_windows.h>

#if defined(__MINGW32__) && defined(MemoryBarrier)
#undef MemoryBarrier

__CRT_INLINE void MemoryBarrier(void)
{
    long Barrier = 0;
    __asm__ __volatile__("xchgl %%eax,%0 "
        :"=r" (Barrier));
}
#endif

#endif