vcpkg: Specify struct member alignment

136 Views Asked by At

I have some old code which is compiled with packing of 1-byte (argument /Zp1) Struct Member Alignment and I'm adding unit testing with gTest to them. I'm using vcpkg to install gTest, but it is compiled using the default setting of 8-byte packing. I'm on Windows with VS2019.

Is it possible to specify which packing to use (parameter /Zp) with vcpkg?

1

There are 1 best solutions below

0
On

As it isn't possible to change the Struct Member Alignment of the libraries with vcpkg during compilation: I had to change my code to use different packing alignments, when including the headers of these libraries.

Everywhere I use the headers of gTest or other libraries provided by vcpkg, I enclosed these with #pragma pack(push, n) and #pragma pack(pop). The value of n depends on default settings, which in my case is 8.

// project specific headers
#include "version.hxx"

// 3rd party libraries (provided by vcpkg)
#pragma pack(push, 8)
#include <gtest/gtest.h>
#include <gtest/gmock.h>
#pragma pack(pop)

// STL
#include <vector>

using std::vector;

It's not the best solution, but at least a workaround to use vcpkg with code, that uses a different packing alignment.