Issue with macro redefinition

I’m including in my project some external content, which seems to also end up including a file called ‘winnt.h’, which is part of Windows (it’s contained in **C:\Program Files (x86)\Windows Kits\8.1\include\um**).

The problem is that this header file contains a definition for a macro that UE4 uses: TEXT

#define TEXT(quote) __TEXT(quote)   // r_winnt

My project still builds, but I can see this causing problems, as it throws up these lines in the output of Visual Studio:

2>C:\Program Files (x86)\Windows Kits\8.1\include\um\winnt.h(536): warning C4005: 'TEXT': macro redefinition
2>c:\program files\epic games\ue_4.18\engine\source\runtime\core\public\HAL/Platform.h(848): note: see previous definition of 'TEXT'

Anyone know anything I can do to avoid conflicts with this redefinition of a macro?


Did you ever figure out how to solve this?

Thank you

1 Like

I had this problem when I was trying to work out how to build and include the OpenVDB library in my UE4 project. Fortunately for me, around the same time Epic released the ProxyLOD plugin, which uses OpenVDB, so I was able to essentially steal their builds/includes of the libraries. I’m not sure how Epic themselves got around this problem though…

Sorry I can’t be more helpful.

I’m also running into this issue trying to access windows specific functionality from within my Unreal Application using #include “Windows/MinWindows”. I’m running 4.22.1 and would still like a solution to this problem if anyone has figured it out.

1 Like

If you are doing WinSock TCP stuff you need a “header sandwich” to instruct Unreal to ignore all the Windows base stuff.

// put this at the top of your .h file above #includes
// UE4: allow Windows platform types to avoid naming collisions
// must be undone at the bottom of this file!
#include "AllowWindowsPlatformTypes.h"
#include "prewindowsapi.h"

… your
… header
… file
… content

// put this at the bottom of the .h file
// UE4: disallow windows platform types
// this was enabled at the top of the file
#include "PostWindowsApi.h"
#include "HideWindowsPlatformTypes.h"


If it helps the full top of our TCP class .h files look like this:

// UE4: allow Windows platform types to avoid naming collisions
// this must be undone at the bottom of this file!
#include "AllowWindowsPlatformTypes.h"
#include "prewindowsapi.h"

#include <exception>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <mutex>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <thread>

#pragma comment (lib, "Ws2_32.lib")
#pragma comment (lib, "Mswsock.lib")
#pragma comment (lib, "AdvApi32.lib")

Yup, as usual would love some ■■■■■■■ useful info here

Hello here :slight_smile:
Sorry if my English is bad, isn’t my language native :slight_smile:

Unreal use already this macro ‘TEXT’
#ifdef UNICODE
#define TEXT(quote) L##quote // wchar_t
#define TEXT(quote) quote // char

But when us included a header windows ‘TEXT’ is already defined…
#include “Winnt.h”

To avoid conflicts we need to delete the macro then redefine it as below:

… your code …

#ifdef TEXT
#undef TEXT // Delete macro UE4

#include “Winnt.h” // Define macro Win32

#ifdef TEXT
#undef TEXT // Delete macro Win32

#define TEXT(quote) __ TEXT(quote) // Define macro UE4

… your code …

Secondary Windows macro ‘__ TEXT’ like ‘TEXT’

I hope it helps you :blush: