Conan package: build failure using c++17 (or later) with MSVC.
vsaulue opened this issue · comments
Description
While trying to use thorvg via conan
in a c++20 project on Windows (Visual Studio Community 17.9.3), the thorvg build fails with the following first error:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\shared\rpcndr.h(203,9): error C2872: 'byte': ambiguous symbol [C:\Users\Vincent\.conan2\p\b\thorvd6d3916f25a7e\b\build-debug\src\25a6634@@thorvg@
sta.vcxproj]
(compiler le fichier source '../../src/src/loaders/ttf/tvgTtfLoader.cpp')
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\shared\rpcndr.h(202,23):
could be 'unsigned char byte'
D:\Programmes\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\cstddef(34,24):
or 'std::byte'
My conan host profile:
[settings]
arch=x86_64
build_type=Debug
compiler=msvc
compiler.cppstd=20
compiler.runtime=dynamic
compiler.runtime_type=Debug
compiler.version=193
os=Windows
[conf]
tools.cmake.cmaketoolchain:generator=Ninja Multi-Config
Reproduction steps
- Open a Visual Studio command prompt
cd
to an empty folder you don't mind pollutingconan remove thorvg
conan install --requires="thorvg/0.13.0" --build=missing -s:h build_type=Debug -s:h compiler.cppstd=20
Full build output
Root cause ?
The C++ standard library provides std::byte since C++17. The Windows header rpcndr.h
defines typedef unsigned char byte;
. A using namespace std; in thorvg causes these types to be ambiguous.
Workaround for users
Force conan to build the thorvg dependency in C++14 for your project, to "undefine" std::byte
. This can be done by adding -s thorvg/*:compiler.cppstd=14
in the conan install
command of your project:
# Build the project's dependencies with C++20 by default, but use C++14 for thorvg.
conan install . -pr:b cpp20-release -pr:h cpp20 -s build_type=Debug --build=missing -s thorvg/*:compiler.cppstd=14
Thank you for raising the issue
Due to build errors caused by the definition overlap between std::byte introduced in C++17 and byte in windows.h, I will resolve this issue by adding the macro #define _HAS_STD_BYTE 0.
just don't include all the headers from windows.h
. Just before windows.h
in tvgTtfLoader.cpp
(and probably in all the source/header files which include windows.h
), define WIN32_LEAN_AND_MEAN
like that:
#ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
it works for me on mingw when using c++20.
thank you for your suggestion. If it is possible to resolve this with the WIN32_LEAN_AND_MEAN macro , this solution seems preferable
thank you for your suggestion. If it is possible to resolve this with the WIN32_LEAN_AND_MEAN macro , this solution seems preferable
@vsaulue Hello, the fix will be applied in v0.13.3. With the version, it will insert the addressed the definition - WIN32_LINEA_AND_MEAN in thorvg "config.h"
Please let us know if you have any trouble with the solution. Thanks.
Hi @hermet,
I don't see a conanfile.py
in the repo to test the Conan packaging, so I tested the build directly with git clone
and meson
instead. I was able to reproduce the errors on v0.13.2
, and they are effectively gone on the main
branch, so it looks good.
Thanks for the quick fix !