Download

Need help to add boost libraries (Asio)

Hello,

For one of my UE 4 project I want to create a client / server system using the library Asio from boost (https://www.boost.org/). Maybe it’s a bad idea to use an external library but I want to know how to do add this library.

First I tried to add it as a Plugin (following this tutorial http://www.valentinkraft.de/includin…real-tutorial/). It didn’t work and I got this error



Could not find definition for module 'BoostLibrary', (referenced via Target -> unreal_engine_4_25_3.Build.cs)


If you want more details check this post where I wrote everything I have done https://www.reddit.com/r/unrealengine/comments/jog9yn/add_boost_library_to_unreal_engine_4/

Then I tried to add it as a Thirdparty in adding (all .hpp and .lib) to my projects and adding those lines to my project.build.cs

my project aborescence



root
|---Binaries
|---Config
|---Source
   |---unreal_engine_4_25_3
      |---unreal_engine_4_25_3.Build.cs
         |---Private
            |--- all my code (.cpp)
         |---Public
            |--- all my code (.h)
         |---ThirdParty
            |---BoostLibrary
               |---include
                  |--- boost
                     |--- all boost .hpp 
               |---lib
                  |--- all boost .lib


unreal_engine_4_25_3.Build.cs:



private string ModulePath
{
     get { return ModuleDirectory; }
}

public void AddPublicAdditionalLibraries(string lib)
{
     PublicAdditionalLibraries.Add(Path.Combine(ModulePath, "Thirdparty/BoostLibrary/lib/" + lib + ".lib"));
}

public unreal_engine_4_25_3(ReadOnlyTargetRules Target) : base(Target)
{
     PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

     PublicSystemIncludePaths.Add(Path.Combine(ModulePath, "Thirdparty/BoostLibrary/include"));

     // Explicitly name the used libraries
     AddPublicAdditionalLibraries("libboost_atomic-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_chrono-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_container-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_context-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_contract-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_coroutine-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_date_time-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_exception-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_fiber-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_filesystem-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_graph-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_iostreams-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_locale-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_log_setup-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_log-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_math_c99f-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_math_c99l-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_math_c99-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_math_tr1f-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_math_tr1l-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_math_tr1-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_nowide-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_prg_exec_monitor-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_program_options-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_random-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_regex-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_serialization-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_stacktrace_noop-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_stacktrace_windbg_cached-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_stacktrace_windbg-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_system-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_test_exec_monitor-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_thread-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_timer-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_type_erasure-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_unit_test_framework-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_wave-vc142-mt-x64-1_74");
     AddPublicAdditionalLibraries("libboost_wserialization-vc142-mt-x64-1_74");

     // Not sure if needed
     PublicDefinitions.Add("_CRT_SECURE_NO_WARNINGS=1");
     PublicDefinitions.Add("BOOST_DISABLE_ABI_HEADERS=1");
     PublicDefinitions.Add("WITH_BOOST_BINDING=1");

     // Needed configurations in order to run Boost
     bUseRTTI = true;
     bEnableExceptions = true;
     //bEnableUndefinedIdentifierWarnings = false;

     PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore" });

     PrivateDependencyModuleNames.AddRange(new string] { });
}


With this method I got this error:



[3/12] src.cpp
This file is deprecated. Please #include <boost/asio/impl/src.hpp> instead.
P:\UnrealProject\projet-coop-cristal\unreal_engine_4_25_3\Source\unreal_engine_4_25_3\Thirdparty\BoostLibrary\include\boost/asio/impl/src.hpp(19): fatal error C1189: #error: Do not compile Asio library source with BOOST_ASIO_HEADER_ONLY defined

AND

[8/12] PlayerCharacter.gen.cpp
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um\winnt.h(603): warning C4005: 'TEXT'?: red?finition de macro
C:\Software\UE_4.25\Engine\Source\Runtime\Core\Public\HAL/Platform.h(1034): note: voir la d?finition pr?c?dente de 'TEXT'
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared
tverp.h(119): error C4668: 'DBG' non d?fini(e) comme pr?processeur ou macro, remplacement par '0' pour '#if/#elif'
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared
tverp.h(126): error C4668: 'BETA' non d?fini(e) comme pr?processeur ou macro, remplacement par '0' pour '#if/#elif'
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared
tverp.h(132): error C4668: 'OFFICIAL_BUILD' non d?fini(e) comme pr?processeur ou macro, remplacement par '0' pour '#if/#elif'
P:\UnrealProject\projet-coop-cristal\unreal_engine_4_25_3\Source\unreal_engine_4_25_3\Thirdparty\BoostLibrary\include\boost/exception/exception.hpp(20): error C4668: '__GNUC__' non d?fini(e) comme pr?processeur ou macro, remplacement par '0' pour '#if/#elif'
P:\UnrealProject\projet-coop-cristal\unreal_engine_4_25_3\Source\unreal_engine_4_25_3\Thirdparty\BoostLibrary\include\boost/exception/exception.hpp(20): error C4668: '__GNUC_MINOR__' non d?fini(e) comme pr?processeur ou macro, remplacement par '0' pour '#if/#elif'
@progress 'Compiling C++ source code...' 75%
[9/12] PlayerCharacter.cpp
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um\winnt.h(603): warning C4005: 'TEXT'?: red?finition de macro
C:\Software\UE_4.25\Engine\Source\Runtime\Core\Public\HAL/Platform.h(1034): note: voir la d?finition pr?c?dente de 'TEXT'
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared
tverp.h(119): error C4668: 'DBG' non d?fini(e) comme pr?processeur ou macro, remplacement par '0' pour '#if/#elif'
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared
tverp.h(126): error C4668: 'BETA' non d?fini(e) comme pr?processeur ou macro, remplacement par '0' pour '#if/#elif'
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared
tverp.h(132): error C4668: 'OFFICIAL_BUILD' non d?fini(e) comme pr?processeur ou macro, remplacement par '0' pour '#if/#elif'
P:\UnrealProject\projet-coop-cristal\unreal_engine_4_25_3\Source\unreal_engine_4_25_3\Thirdparty\BoostLibrary\include\boost/exception/exception.hpp(20): error C4668: '__GNUC__' non d?fini(e) comme pr?processeur ou macro, remplacement par '0' pour '#if/#elif'
P:\UnrealProject\projet-coop-cristal\unreal_engine_4_25_3\Source\unreal_engine_4_25_3\Thirdparty\BoostLibrary\include\boost/exception/exception.hpp(20): error C4668: '__GNUC_MINOR__' non d?fini(e) comme pr?processeur ou macro, remplacement par '0' pour '#if/#elif'


Anyone can help me ? or give me a guide/tutorial about how to add a thirdparty librarie or how to add boost libs ?
It has been a month I’m on it…

Thanks for your time, have a great day.

I stopped using Boost but I did get it working. The code in the build.cs was pretty minimal. I will so some digging in my source control to see if I missed anything.

Directory structure for the project:
Binaries
Config
Content
Source
ThirdParty ← My directory

  • boost <—

The directory for the engine is in a separate directly entirely on my setup.



private string ThirdPartyPath
{
get { return Path.GetFullPath(Path.Combine(ModuleDirectory, "../../ThirdParty/")); }
}

public <projectname>(ReadOnlyTargetRules Target) : base(Target)
{
PublicIncludePaths.Add(Path.Combine(ThirdPartyPath, "boost"));  <-- same name as directory "boost"
PublicSystemIncludePaths.Add(Path.Combine(ThirdPartyPath, "boost"));
}


Don’t forget the usings:


using System.IO;
using System.Collections.Generic;