LoginSignup
1
1

More than 3 years have passed since last update.

UE4のTEXTマクロ多重定義回避

Last updated at Posted at 2020-09-28

先行記事

UnrealC++のマクロ多重定義の回避方法
https://qiita.com/Naotsun/items/a97af1e0ff22a75ce4d9

背景

UE4のC++で某ライブラリを使おうとしたらTEXT多重定義でハマって、日本語の記事が上記のしかなったので補足。

UE4フォーラムの#5コメントにすべてが書いてあった。
https://forums.unrealengine.com/development-discussion/c-gameplay-programming/1446900-issue-with-macro-redefinition

回避方法1

先行記事にも書いてある方法。AllowWindowsPlatformTypes.hHideWindowsPlatformTypes.h
でインクルードしているヘッダーを囲む。

この方法ではWindows特有の定義のエラーを回避できるらしいが、使おうとしたライブラリでWinnt.hで定義されている関数が使われていたのでビルド通らず。

#include "AllowWindowsPlatformTypes.h"

//あなたが使っているヘッダーファイル

#include "HideWindowsPlatformTypes.h"

回避方法2

上記のフォーラムのコメント#5では回避方法1, 2の両方を使っていたがこちらだけにしたらビルドが通った。

#include "PreWindowsApi.h"

//あなたが使っているヘッダーファイル

#include "PostWindowsApi.h"

回避方法3

根本的解決。C++での多重定義回避の方法らしい。
https://docs.microsoft.com/ja-jp/cpp/preprocessor/hash-ifdef-and-hash-ifndef-directives-c-cpp?view=vs-2019

TEXTマクロを該当のcppでだけ宣言を宣言解除する。

#ifdef TEXT //TEXTマクロが宣言されているときだけ通る
#undef TEXT //TEXTマクロを宣言解除する

//使いたいTEXTマクロが多重定義されていると言われるヘッダーファイル

#endif
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1