Download

Can't use Boost libraries with unreal

Hi, I’m trying to use the Boost libraries within Unreal,
but I always get the error


Cannot open source file "boost/interprocess/allocators/allocator.hpp"


and so on.

This is my build file


using System.IO;
using UnrealBuildTool;

public class varest : ModuleRules
{
    private string ModulePath
    {
        get { return ModuleDirectory; }
    }

    private string ThirdPartyPath
    {
        get { return Path.GetFullPath(Path.Combine(ModulePath, "../../ThirdParty/")); }
    }
    public varest(TargetInfo Target)
	{
		PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay" });

		PrivateDependencyModuleNames.AddRange(new string] {  });

        // Uncomment if you are using Slate UI
        // PrivateDependencyModuleNames.AddRange(new string] { "Slate", "SlateCore" });

        // Uncomment if you are using online features
        // PrivateDependencyModuleNames.Add("OnlineSubsystem");

        // To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
        LoadBoost(Target);
    }

    public bool LoadBoost(TargetInfo Target)
    {
        bool isLibrarySupported = false;

        if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32))
        {
            isLibrarySupported = true;

            string PlatformString = (Target.Platform == UnrealTargetPlatform.Win64) ? "x64" : "x86";
        }

        if (isLibrarySupported)
        {
            // Include path
           PublicIncludePaths.Add(Path.Combine(ThirdPartyPath, "Boost", "Includes", "boost"));
        }

        Definitions.Add(string.Format("WITH_BOOST_BINDING={0}", isLibrarySupported ? 1 : 0));

        return isLibrarySupported;
    }

}

Can some one help? Thanks!

Ok, I solved the problem, but now I’m having further issues:


2>E:	emp	estproject\ThirdParty\Includes\boost/intrusive/slist.hpp(1926): error C4003: not enough actual parameters for macro 'check'
2>E:	emp	estproject\ThirdParty\Includes\boost/intrusive/slist.hpp(1926): error C4003: not enough actual parameters for macro 'check'
2>E:	emp	estproject\ThirdParty\Includes\boost/intrusive/slist.hpp(1926): error C2062: type 'void' unexpected
2>  E:	emp	estproject\ThirdParty\Includes\boost/intrusive/slist.hpp(2127): note: see reference to class template instantiation 'boost::intrusive::slist_impl<ValueTraits,SizeType,BoolFlags,HeaderHolder>' being compiled
2>E:	emp	estproject\ThirdParty\Includes\boost/intrusive/slist.hpp(1926): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
2>E:	emp	estproject\ThirdParty\Includes\boost/intrusive/slist.hpp(1927): error C4430: missing type specifier - int assumed. Note: C++ does not support default-intE:	emp	estproject\ThirdParty\Includes\boost/intrusive/slist.hpp(1926): error C2062: type 'void' unexpected
2>
2>E:	emp	estproject\ThirdParty\Includes\boost/intrusive/slist.hpp(1927): error C2059: syntax error: '{'E:	emp	estproject\ThirdParty\Includes\boost/intrusive/slist.hpp(2127): note: see reference to class template instantiation 'boost::intrusive::slist_impl<ValueTraits,SizeType,BoolFlags,HeaderHolder>' being compiled
2>
2>E:	emp	estproject\ThirdParty\Includes\boost/intrusive/slist.hpp(1927): error C2334: unexpected token(s) preceding '{'; skipping apparent function bodyE:	emp	estproject\ThirdParty\Includes\boost/intrusive/slist.hpp(1926): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
2>
2>E:	emp	estproject\ThirdParty\Includes\boost/intrusive/slist.hpp(1927): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
2>E:	emp	estproject\ThirdParty\Includes\boost/intrusive/slist.hpp(1927): error C2059: syntax error: '{'
2>E:	emp	estproject\ThirdParty\Includes\boost/intrusive/slist.hpp(1927): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
2>E:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(1626): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::NtQuerySystemInformation_t'
2>          Calling this function through the result pointer may cause your program to failE:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(1626): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::NtQuerySystemInformation_t'
2>          Calling this function through the result pointer may cause your program to fail
2>
2>E:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(1833): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::NtSetInformationFile_t'
2>          Calling this function through the result pointer may cause your program to fail
2>E:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(1833): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::NtSetInformationFile_t'
2>          Calling this function through the result pointer may cause your program to fail
2>E:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(1835): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::NtQueryObject_t'
2>          Calling this function through the result pointer may cause your program to fail
2>E:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(1835): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::NtQueryObject_t'
2>          Calling this function through the result pointer may cause your program to fail
2>E:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(1907): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::NtOpenFile_t'
2>          Calling this function through the result pointer may cause your program to fail
2>E:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(1907): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::NtOpenFile_t'
2>          Calling this function through the result pointer may cause your program to failE:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(1908): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::NtClose_t'
2>          Calling this function through the result pointer may cause your program to fail
2>
2>E:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(1908): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::NtClose_t'
2>          Calling this function through the result pointer may cause your program to fail
2>E:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(2287): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::NtQuerySection_t'
2>          Calling this function through the result pointer may cause your program to failE:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(2287): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::NtQuerySection_t'
2>          Calling this function through the result pointer may cause your program to fail
2>
2>E:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(2300): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::NtQuerySemaphore_t'
2>          Calling this function through the result pointer may cause your program to failE:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(2300): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::NtQuerySemaphore_t'
2>          Calling this function through the result pointer may cause your program to fail
2>
2>E:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(2311): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::NtQueryTimerResolution_t'
2>          Calling this function through the result pointer may cause your program to fail
2>E:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(2311): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::NtQueryTimerResolution_t'
2>          Calling this function through the result pointer may cause your program to fail
2>E:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(2318): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::NtSetTimerResolution_t'
2>          Calling this function through the result pointer may cause your program to fail
2>E:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(2318): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::NtSetTimerResolution_t'
2>          Calling this function through the result pointer may cause your program to failE:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(2325): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::QueryPerformanceCounter_t'
2>          Calling this function through the result pointer may cause your program to fail
2>
2>E:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(2332): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::QueryPerformanceFrequency_t'
2>          Calling this function through the result pointer may cause your program to failE:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(2325): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::QueryPerformanceCounter_t'
2>          Calling this function through the result pointer may cause your program to fail
2>
2>E:	emp	estproject\ThirdParty\Includes\boost/interprocess/detail/win32_api.hpp(2332): warning C4191: 'type cast': unsafe conversion from 'boost::interprocess::winapi::farproc_t' to 'boost::interprocess::winapi::QueryPerformanceFrequency_t'
2>          Calling this function through the result pointer may cause your program to fail

The problem is that UE4 defines a lot of macros like “check(…)” that can also appear in the boost libs.
I always find it hard to include large source libraries because of this. Basically you have to go into the boost sources and make sure to rename all problematic variables/functions/macros.

Maybe it would be easier if you package the boost functionality you need into a separate lib (e.g. DLL) that you can load and call into.

And maybe there is some option in your build.cs that I do not know of that allows you to disable the UE4 stuff for some files.

Thanks for the help, but I surrender, it’s a real mess, I will try without boost!

I’m using boost (albeit a subset) in a UE4 project, including boost.Geometry which is incompatible with UE4’s check macro.
Try something like the following (you may have to modify it if you need to compile with more than just VS):



// Undefine to avoid conflicts
#pragma push_macro("check")
#undef check

#include "some_stuff_from_boost.hpp"

// Redefine check macro
#pragma pop_macro("check")


2 Likes

Thank you very much, I’ll try!

Worked like a charm. Thank you.