I would like to use bits from the Boost library. I have added Boost into PrivateDependencyModuleNames within my plugin’s build.cs file. That is something I have seen in other plugins (for example USDSchemas.build.cs)
PrivateDependencyModuleNames.AddRange(
new string[]
{
"CoreUObject",
"Engine",
"Slate",
"SlateCore",
"Boost",
"Shared",
// ... add private dependencies that you statically link with here ...
}
);
However, when I add an include of binomial heap (specifically include “boost/heap/binomial_heap.hpp”) into my plugin, the project fails to compile with significant number of compilation errors. Here is a small excerpt, full build log is attached
12>[1/6] Compile [x64] NPCStateSearchNodePtrCompare.cpp
12>E:\wil\Engine\Source\ThirdParty\Boost\Deploy\boost-1.85.0\include\boost\core\pointer_traits.hpp(128,1): error C2988: unrecognizable template declaration/definition
12> static auto check(int) -> result<decltype(O::pointer_to(source()))>;
12>^
12>E:\wil\Engine\Source\ThirdParty\Boost\Deploy\boost-1.85.0\include\boost\core\pointer_traits.hpp(128,1): note: the template instantiation context (the oldest one first) is
12>E:\wil\Engine\Source\ThirdParty\Boost\Deploy\boost-1.85.0\include\boost\core\pointer_traits.hpp(119,7): note: while compiling class template 'boost::detail::ptr_to_expr'
12>class ptr_to_expr {
12> ^
Is there some step or setting that I am missing to get the boost library working correctly? Or it is the case that such usage of boost library is not supported in Unreal engine?
These compilation issues are a result of Boost defining its own version of “check” that conflicts with the one defined by the engine. The USD-related code you mentioned provides a workaround for this by supplying “start” and “end” headers that are intended to wrap all includes that might end up bringing in Boost or other third-party library headers.
If you’re setup with access to Unreal Engine source on GitHub, the “start” header is here, and in particular the code handling check:
To replicate this in your own plugin and include that particular Boost header, I would suggest trying to include it like this:
THIRD_PARTY_INCLUDES_START
#pragma push_macro("check")
#undef check // Boost defines its own version of check, so undef UE's to prevent conflicts
#include "boost/heap/binomial_heap.hpp"
#pragma pop_macro("check")
THIRD_PARTY_INCLUDES_END
Having said all that, we really only ship an installation of Boost with the engine to support third-party libraries that depend on it, which at this point is primarily just OpenVDB since OpenUSD no longer depend on Boost in the ue5-main branch. We don’t really advise making extensive use of Boost in conjunction with engine/plugin code, and might not be able to provide much in the way of support if using Boost exposes other compilation or functionality issues.
thanks for the reply, your workaround works. Also thanks for the warning about Boost support in UE. We will discuss it internally whether to use Boost or not. Historically we are quite accustomed to use few useful containers from Boost like flat_map, flat_set but we can replace them. Only in a few other case we use something else, like the binomial heap I mentioned before.
Great, glad to hear that workaround worked for you.
And yeah, our coding standards are fairly restrictive even on the C++ standard library, so it would probably be best to similarly avoid Boost if you can, but you’re of course free to use whatever makes the most sense for your projects.
There’s more info about this under “Use of standard libraries” on the coding standards page here: