Pietro
Pietro

Reputation: 13172

Compile time error from a Qt file: expected unqualified-id before ')' token

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

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?

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

Upvotes: 4

Views: 7835

Answers (4)

László Papp
László Papp

Reputation: 53175

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?

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

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

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.

We had used something like this in our project a couple of years ago when we were writing thread-safe singletons based on 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.

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

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

and

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.

Upvotes: 5

Devolus
Devolus

Reputation: 22104

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.

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.

#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

Upvotes: 1

Danny Smith
Danny Smith

Reputation: 1046

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.

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

in src/gui/opengl/qopengl.h line 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 always needs this to ensure that APIENTRY gets defined
#if defined(Q_OS_WIN)
# include <QtCore/qt_windows.h>
# undef MemoryBarrier
#endif

Upvotes: 7

adler
adler

Reputation: 969

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

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

Upvotes: 1

Related Questions