# Getting errors in build, after I include torch in my cpp file

**URL:** <https://forums.unrealengine.com/t/getting-errors-in-build-after-i-include-torch-in-my-cpp-file/2382196>\
**Category:** C++\
**Tags:** unreal-engine, Machine-Learning, CPP\
**Created:** [March 9, 2025, 5:40pm UTC](https://forums.unrealengine.com/t/getting-errors-in-build-after-i-include-torch-in-my-cpp-file/2382196 "2025-03-09T17:40:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![KKJMJ9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KKJMJ9](https://forums.unrealengine.com/u/KKJMJ9)\
**Post date:** [March 9, 2025, 5:40pm UTC](https://forums.unrealengine.com/t/getting-errors-in-build-after-i-include-torch-in-my-cpp-file/2382196/1 "2025-03-09T17:40:22Z")

</div>

When i add # include \<torch/torch.h\> and then build project i get errors/warns like:

```auto
Unreal Projects\NoxViridus\eLibs\libtorch\include\c10\macros\Macros.h(495): error C4668: __GNUC__ is not defined as a preprocessor macro; for: #if/#elif is replaced by zero (0).
Unreal Projects\NoxViridus\eLibs\libtorch\include\c10\util\Lazy.h(32): error C2988: unrecognizable template declaration/definition
Unreal Projects\NoxViridus\eLibs\libtorch\include\c10\util\Lazy.h(32): note: the context for creating template instances (oldest first) is
Unreal Projects\NoxViridus\eLibs\libtorch\include\c10\util\Lazy.h(50): error C2334: Before: { are unexpected tokens; the part that looks like the function body is skipped.
\Unreal Projects\NoxViridus\eLibs\libtorch\include\c10\core\impl\DeviceGuardImplInterface.h(371): note: Consider using explicit overriding or comparing to nullptr if you want this warning not to appear.
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\INCLUDE\atomic(1074): note: see declaration: std::_Atomic_storage<_Ty,8>::_TVal
1> with
1> [
1> _Ty=const c10::impl::DeviceGuardImplInterface *
1> ]

```

and it’s more of it like 15000 chars

the build then end with:

```auto
1>Trace file written to C:/Users/jmeno/AppData/Local/UnrealBuildTool/Log.uba with size 48.4kb
1>Total time in Unreal Build Accelerator local executor: 39.94 seconds
1>Total execution time: 47.39 seconds
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.MakeFile.Targets(44,5): error MSB3073: Command "C:\Program Files\Epic Games\UE_5.5\Engine\Build\BatchFiles\Build. bat" NoxViridus Win64 Development -Project="C:\Users\name\OneDrive\Documents\Unreal Projects\NoxViridus\NoxViridus.uproject" -WaitMutex -FromMsBuild -architecture=x64 was terminated with code 6.
1>The build of the NoxViridus.vcxproj project was completed: ERROR.
========== Build: successful: 0, failed: 1, current: 0, skipped: 0 ==========
========== Build completed at 18:24 and took 48.596 seconds ==========

```

When i remove the # include \<torch/torch.h\> it build succesfull and i downloaded libtorch stable(2.6.0),windows,libtorch,c++/java, cuda 12.6, RELEASE

my NoxViridus.Build.cs:

```auto
/*
// Fill out your copyright notice in the Description page of Project Settings.

using UnrealBuildTool;
//using System.IO;

public class NoxViridus : ModuleRules
{
    public NoxViridus(ReadOnlyTargetRules Target) : base(Target)
    {
        PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

        // Povolení RTTI a případně i výjimek (pokud je libtorch potřebuje)
        //bUseRTTI = true;
        //bEnableExceptions = true;

        // Public dependencies
        PublicDependencyModuleNames.AddRange(new string[]
        {
            "Core",
            "CoreUObject",
            "Engine",
            "InputCore",
            "OnlineSubsystem",
            "OnlineSubsystemUtils"
        });

        //PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "/eLibs/libtorch/include"));
        //PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "/Users/name/OneDrive/Dokumenty/Unreal Projects/NoxViridus/eLibs/libtorch/include"));
        //PublicIncludePaths.Add("C:/Users/name/OneDrive/Dokumenty/Unreal Projects/NoxViridus/eLibs/libtorch/include");

        // Přidáme také specifickou cestu k API hlavičkám, kde je např. torch.h.
        //PublicIncludePaths.Add("C:/Users/name/OneDrive/Dokumenty/Unreal Projects/NoxViridus/eLibs/libtorch/include/torch/csrc/api/include");

        // Nastavení knihovny
        //PublicAdditionalLibraries.Add("C:/Users/name/OneDrive/Dokumenty/Unreal Projects/NoxViridus/eLibs/libtorch/lib/torch.lib");

        //PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "/eLibs/libtorch/lib"));
        //PublicAdditionalLibraries.Add("torch.lib");

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

        // Uncomment if you are using additional private modules
        // PrivateDependencyModuleNames.Add("OnlineSubsystem");

        // Add Steam support if needed in your uproject file
        // To include OnlineSubsystemSteam, enable it in the plugins section of your .uproject file
    }
}

*/
using UnrealBuildTool;
using System.IO;

public class NoxViridus : ModuleRules
{
    public NoxViridus(ReadOnlyTargetRules Target) : base(Target)
    {
        PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

        // Povolení RTTI a výjimek, pokud je libtorch potřebuje
        bUseRTTI = true;
        bEnableExceptions = true;
        CppStandard = CppStandardVersion.Cpp17;

        // Public dependencies
        PublicDependencyModuleNames.AddRange(new string[]
        {
            "Core",
            "CoreUObject",
            "Engine",
            "InputCore",
            "OnlineSubsystem",
            "OnlineSubsystemUtils"
        });

        // Cesta k libtorch knihovnám
        string LibTorchBaseDir = Path.Combine(ModuleDirectory, "../../eLibs/libtorch/");

        if (Target.Platform == UnrealTargetPlatform.Win64)
        {
            // Přidání include cest
            PublicIncludePaths.Add(Path.Combine(LibTorchBaseDir, "include"));
            PublicIncludePaths.Add(Path.Combine(LibTorchBaseDir, "include/torch/csrc/api/include"));

            // Přidání statických a dynamických knihoven
            string LibDir = Path.Combine(LibTorchBaseDir, "lib");
            string[] LibFiles = Directory.GetFiles(LibDir, "*.lib", SearchOption.AllDirectories);
            PublicAdditionalLibraries.AddRange(LibFiles);

            // Přidání runtime závislostí pro DLL
            string[] DllFiles = Directory.GetFiles(LibDir, "*.dll", SearchOption.AllDirectories);
            foreach (string DllPath in DllFiles)
            {
                string DllName = Path.GetFileName(DllPath);
                RuntimeDependencies.Add("$(TargetOutputDir)/" + DllName, DllPath);
                PublicDelayLoadDLLs.Add(DllName);
            }
        }
        PublicDefinitions.Add("TORCH_USE_CXX11_ABI=0");
    }
}

```

thanks for any replies

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [March 9, 2025, 10:24pm UTC](https://forums.unrealengine.com/t/getting-errors-in-build-after-i-include-torch-in-my-cpp-file/2382196/2 "2025-03-09T22:24:25Z")

</div>

Look into

> **[Integrating Third-Party Libraries into Unreal Engine | Unreal Engine 5.5...](https://dev.epicgames.com/documentation/en-us/unreal-engine/integrating-third-party-libraries-into-unreal-engine)**
>
> Integrating third-party libraries into Unreal Engine

Make sure your plugin internals that conflict with Unreal’s defines are marked and isolated with

THIRD\_PARTY\_INCLUDES\_START  
and  
THIRD\_PARTY\_INCLUDES\_END

---

<div class="post-metadata">

**Author:** ![KKJMJ9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KKJMJ9](https://forums.unrealengine.com/u/KKJMJ9)\
**Post date:** [March 10, 2025, 6:14am UTC](https://forums.unrealengine.com/t/getting-errors-in-build-after-i-include-torch-in-my-cpp-file/2382196/3 "2025-03-10T06:14:53Z")

</div>

Co if i understood IT corectly i need add in my project new plugin from thirt-party and inside of that plugin create .Build.cs file. And in to it write addresses to include lib folders ect. of libtorch?

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [March 10, 2025, 6:55am UTC](https://forums.unrealengine.com/t/getting-errors-in-build-after-i-include-torch-in-my-cpp-file/2382196/4 "2025-03-10T06:55:47Z")

</div>

It could be a plugin or a module but it is good practice to isolate third party code, so that it doesn’t have conflicting defines and macros.

---

<div class="post-metadata">

**Author:** ![KKJMJ9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KKJMJ9](https://forums.unrealengine.com/u/KKJMJ9)\
**Post date:** [March 10, 2025, 2:50pm UTC](https://forums.unrealengine.com/t/getting-errors-in-build-after-i-include-torch-in-my-cpp-file/2382196/5 "2025-03-10T14:50:38Z")

</div>

when i try to create third party library plugin template it fails to generate project files and deletes the plugin folder:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/9/1/69138a1c8507317980a262daef1f1b860031d557.png)

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [March 10, 2025, 5:25pm UTC](https://forums.unrealengine.com/t/getting-errors-in-build-after-i-include-torch-in-my-cpp-file/2382196/6 "2025-03-10T17:25:29Z")

</div>

This tutorial pretty extensively explains incorporating thirdparty code into a project.

Note it’s from youtube from outside of the forum.

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/9/a/b9ab380b20dd24af5fc093a285c599df2643ac3c.jpeg "11. UnrealBuildTool modules & linking third-party code") ](https://www.youtube.com/watch?v=D0nQnUmvpk8)
