简体   繁体   中英

vcpkg: Specify struct member alignment

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM