Question

The Issue

I have a Qt application that is made in Visual Studio 2005 which uses a fair amount of other libraries which are all compiled with a struct member alignment of 1. I'm also pretty sure that Qt default uses a struct member alignment of 0.

This obviously causes issues when i compile my application with a struct member alignment of 0 (Other libraries will fail) or 1(Qt will fail).

What I've tried

Compiler flags in the projects.pro file

  1. I downloaded the source code of Qt.
  2. I added the following at the top of the projects.pro file

    QMAKE_CXXFLAGS_DEBUG += -Zp1 QMAKE_CXXFLAGS_RELEASE += -Zp1

  3. I used the visual studio commandline to start the configure.exe which creates the makefiles.

  4. I started nmake which then compiles Qt.

This causes Qt to compile with a struct member alignment of 0. Maybe -Zp1 (I also tried /Zp1) is not recognized by the compiler but this would surprise me because this is how Visual Studio uses it in its property pages:

Struct Member Alignment 1

compiler flags in the makefile

Now is was looking into doing about the same:

  1. Downloading the source code of Qt.
  2. Running configure.exe in the visual studio commandline.

At this point I have the makefile which I can alter so that it can use a struct member alignment of 1. No success here.

My Question

How can i compile Qt for Visual Studio 2005 with a struct member alignment of 1?

Was it helpful?

Solution

Qt does not support a struct member aligment different from 8 (Default). The only way to solve this is by using #pragma pack:

#pragma pack( [ show ] | [ push | pop ] [, identifier ] , n  )

Surround all Qt code and includes with a push and pop:

#pragma pack(push, 8)
...
#pragma pack(pop)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top