Errors when including third party library

Hey,
I’ve been trying to include the “armadillo” library into my ue5 project, by simply adding include path in build.cs file and than using #include armadillo. After trying to build the project from vs I get multiple errors that seem to be of the same kind.

However, if I try to do the same in a new visual studio project (so not inside ue5), it works just fine. (using the same v142 toolchain and same sdk)

This is an example of the code, where an error occurs:
image

This is the output log:

Build started...
1>------ Build started: Project: GenAB, Configuration: Development_Editor x64 ------
1>Running UnrealBuildTool: dotnet "..\..\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.dll" GenABEditor Win64 Development -Project="C:\Users\mange\Documents\Unreal Projects\GenAB\GenAB.uproject" -WaitMutex -FromMsBuild
1>Log file: C:\Users\mange\AppData\Local\UnrealBuildTool\Log.txt
1>Building GenABEditor...
1>Using Visual Studio 2019 14.29.30147 toolchain (C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133) and Windows 10.0.18362.0 SDK (D:\Delphi WindowsSDK).
1>Determining max actions to execute in parallel (6 physical cores, 12 logical cores)
1>  Executing up to 6 processes, one per physical core
1>  Requested 1.5 GB free memory per action, 4.89 GB available: limiting max parallel actions to 3
1>Building 4 actions with 3 processes...
1>[1/4] Link UnrealEditor-GenAB.dll cancelled
1>[2/4] Link UnrealEditor-GenAB.lib cancelled
1>[3/4] WriteMetadata GenABEditor.target cancelled
1>[4/4] Compile GeneralAgentBehaviour.cpp
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(39): error C2988: unrecognizable template declaration/definition
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(43): note: see reference to class template instantiation 'arma::is_Mat_fixed_only<T>' being compiled
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(39): error C2059: syntax error: '<end Parse>'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(39): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(40): error C2988: unrecognizable template declaration/definition
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(40): error C2059: syntax error: '<end Parse>'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(40): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(53): error C2988: unrecognizable template declaration/definition
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(57): note: see reference to class template instantiation 'arma::is_Row_fixed_only<T>' being compiled
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(53): error C2059: syntax error: '<end Parse>'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(53): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(54): error C2988: unrecognizable template declaration/definition
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(54): error C2059: syntax error: '<end Parse>'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(54): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(67): error C2988: unrecognizable template declaration/definition
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(71): note: see reference to class template instantiation 'arma::is_Col_fixed_only<T>' being compiled
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(67): error C2059: syntax error: '<end Parse>'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(67): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(68): error C2988: unrecognizable template declaration/definition
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(68): error C2059: syntax error: '<end Parse>'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(68): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(1270): error C2988: unrecognizable template declaration/definition
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(1274): note: see reference to class template instantiation 'arma::has_nested_op_traits<T>' being compiled
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(1270): error C2059: syntax error: '<end Parse>'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(1270): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(1271): error C2988: unrecognizable template declaration/definition
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(1271): error C2059: syntax error: '<end Parse>'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(1271): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(1282): error C4002: too many arguments for function-like macro invocation 'check'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(1282): error C2988: unrecognizable template declaration/definition
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(1286): note: see reference to class template instantiation 'arma::has_nested_glue_traits<T>' being compiled
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(1282): error C2059: syntax error: '<end Parse>'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(1282): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(1283): error C2988: unrecognizable template declaration/definition
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(1283): error C2059: syntax error: '<end Parse>'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(1283): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\promote_type.hpp(198): error C4003: not enough arguments for function-like macro invocation 'check'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\promote_type.hpp(198): error C4003: not enough arguments for function-like macro invocation 'UE_CHECK_IMPL'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\promote_type.hpp(198): error C2062: type 'void' unexpected
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\promote_type.hpp(204): note: see reference to class template instantiation 'arma::promote_type<T1,T2>' being compiled
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\promote_type.hpp(198): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\promote_type.hpp(199): error C2059: syntax error: '{'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\promote_type.hpp(199): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_plus.hpp(154): error C4003: not enough arguments for function-like macro invocation 'check'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_plus.hpp(154): error C4003: not enough arguments for function-like macro invocation 'UE_CHECK_IMPL'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_plus.hpp(279): error C4003: not enough arguments for function-like macro invocation 'check'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_plus.hpp(279): error C4003: not enough arguments for function-like macro invocation 'UE_CHECK_IMPL'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_minus.hpp(163): error C4003: not enough arguments for function-like macro invocation 'check'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_minus.hpp(163): error C4003: not enough arguments for function-like macro invocation 'UE_CHECK_IMPL'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_minus.hpp(309): error C4003: not enough arguments for function-like macro invocation 'check'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_minus.hpp(309): error C4003: not enough arguments for function-like macro invocation 'UE_CHECK_IMPL'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_times.hpp(176): error C4003: not enough arguments for function-like macro invocation 'check'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_times.hpp(176): error C4003: not enough arguments for function-like macro invocation 'UE_CHECK_IMPL'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_times.hpp(241): error C4003: not enough arguments for function-like macro invocation 'check'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_times.hpp(241): error C4003: not enough arguments for function-like macro invocation 'UE_CHECK_IMPL'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_times.hpp(435): error C4003: not enough arguments for function-like macro invocation 'check'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_times.hpp(435): error C4003: not enough arguments for function-like macro invocation 'UE_CHECK_IMPL'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_schur.hpp(70): error C4003: not enough arguments for function-like macro invocation 'check'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_schur.hpp(70): error C4003: not enough arguments for function-like macro invocation 'UE_CHECK_IMPL'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_schur.hpp(241): error C4003: not enough arguments for function-like macro invocation 'check'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_schur.hpp(241): error C4003: not enough arguments for function-like macro invocation 'UE_CHECK_IMPL'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_div.hpp(148): error C4003: not enough arguments for function-like macro invocation 'check'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_div.hpp(148): error C4003: not enough arguments for function-like macro invocation 'UE_CHECK_IMPL'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_cube_plus.hpp(142): error C4003: not enough arguments for function-like macro invocation 'check'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_cube_plus.hpp(142): error C4003: not enough arguments for function-like macro invocation 'UE_CHECK_IMPL'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_cube_minus.hpp(142): error C4003: not enough arguments for function-like macro invocation 'check'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_cube_minus.hpp(142): error C4003: not enough arguments for function-like macro invocation 'UE_CHECK_IMPL'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_cube_schur.hpp(60): error C4003: not enough arguments for function-like macro invocation 'check'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_cube_schur.hpp(60): error C4003: not enough arguments for function-like macro invocation 'UE_CHECK_IMPL'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_cube_div.hpp(126): error C4003: not enough arguments for function-like macro invocation 'check'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\operator_cube_div.hpp(126): error C4003: not enough arguments for function-like macro invocation 'UE_CHECK_IMPL'
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(42): error C2065: 'check': undeclared identifier
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(42): error C2275: 'T': illegal use of this type as an expression
1>C:\mlpack\armadillo-11.4.2\include\armadillo_bits\traits.hpp(42): fatal error C1903: unable to recover from previous error(s); stopping compilation
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.MakeFile.Targets(45,5): error MSB3073: The command ""C:\Program Files\Epic Games\UE_5.1\Engine\Build\BatchFiles\Build.bat" GenABEditor Win64 Development -Project="C:\Users\mange\Documents\Unreal Projects\GenAB\GenAB.uproject" -WaitMutex -FromMsBuild" exited with code 6.
1>Done building project "GenAB.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

That’s why modern cpp avoids macros as possible :slight_smile:
Looks like a names conflict. UE defines a macro check.
Before including 3rd-party header, try undefine it, something like:

// include UE headers
// ...
// and lastly:
#ifdef check
#undef check
#include "3rdpartlib.h"

That was it. Thank you a lot man. I’ve been stuck on this for days.

This generally works, but can make problem again if your later code calls some UE functions which use “original” check macro.

Better solution is to use #pragma push_macro/#pragma pop_macro. AFAIK this is supported by all big-three compilers (GCC,Clang,MSVC).

#include "some_unreal_header.h"
#pragma push_macro("check")   // store 'check' macro current definition
#undef check  // undef to avoid conflicts
#include "some_3rd_party_lib.h"
#pragma pop_macro("check")  // restore definition
3 Likes