x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Constant Library Conflicts

There is a plague in the unreal code base known as macros. You guys name them with commonplace words like "check" (the most frequent offender in my experience) and that's a problem. There are documented issues with HUGELY popular libraries not the least of which includes OpenCV and Boost, they have objects named "check". Having a macro named "check" means that as a preprocessor directive, it overwrites library header files mentioning of "check", namespaces do not weigh in. What needs to be done is either renaming your macros such that they won't conflict so often (eg prefixing), OR reimplement the macros using templates which obey namespace rules.

Product Version: UE 4.10
Tags:
more ▼

asked Mar 18 '16 at 01:34 PM in Bug Reports

avatar image

SteamyThePunk
38 4 6 12

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

6 answers: sort voted first

Hi, if you're still trying to get third party code to work in your unreal project, I'd suggest precompiling a unreal friendly wrapper library that an unreal plugin can reference.

So essentially you have your unreal game, which includes an unreal plugin, which references an unreal friendly wrapper library, which contains the third party code.... Yeah, it's garbage.

I suggest if you're trying to do anything in unreal other than exactly what is built into unreal... don't use unreal.

more ▼

answered Dec 14 '16 at 05:41 PM

avatar image

SteamyThePunk
38 4 6 12

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Hello SteamyThePunk,

As we don't support those extra libraries, we most likely won't be making any direct changes to the source code to change this at this time. However, I would suggest looking at AllowWindowsPlatformTypes.h and HideWindowsPlatformTypes.h and how they are handling the macros defined there. This should be able to give you an idea of how to incorporate the Boost library's macros that are conflicting.

more ▼

answered Mar 24 '16 at 05:51 PM

avatar image

Matthew J ♦♦ STAFF
28.7k 525 85 400

avatar image SteamyThePunk Mar 25 '16 at 12:17 PM

Matthew, thanks very much for providing a prospective answer, but I don't appreciate you marking it as THE answer, because I wouldn't accept this as an answer.

That you don't support a third party library goes without saying, but I don't think it's asking too much to ask that epic should be making code that is in following with C++ standards. The Boost Library doesn't use such commonplace named macros. Unreal's macros are conflicting with boost function names. Unreal macros are conflicting with popular libraries' symbol names, which is causing confusion among many developers in the unreal community, as to why they can't use a given library with unreal, and the errors they get don't necessarily tell them that the problem is an unreal macro screwing up the library's code. If you have a macro called "check" and someone wants to make a function called "check" that causes a very difficult to debug conflict. These are problems that should be addressed, not just shrugged off. I shouldn't be expected to modify Boost to work with unreal, I should expect Unreal not conflict with C++ standards. Boost being written by the same people who write the STL, and many modules of Boost being incorporated to the STL, of all libraries you SHOULD avoid conflicting with, STL and Boost are at the top of that list.

avatar image Matthew J ♦♦ STAFF Mar 25 '16 at 12:24 PM

Please be aware that the answer being marked as accepted is an automatic thing from answerhub that happens when staff members post an answer, mainly for tracking reasons.

I understand your stance in this matter. Due to that, I'll enter a feature request to have these macros changed. Please understand however, that it may not happen not solely due to how we use these macros, but how all of our users have been using them as well. I'll be sure to update you on the status of the request whenever its updated.

In the meantime, could you give a list of all of the conflicting macros that you've encountered, other than "check"? This is to ensure that we don't miss any if we do decide to make these changes.

avatar image SteamyThePunk Mar 26 '16 at 07:34 PM

At present it is a problem I've only run into concerning check. It seems that I and many who have attempted to use OpenCV have run into the check macro collision, I've seen more than a couple people run into the issue post about it and never get a solution, presumably they deserted their efforts. I'm running into it again trying to work with Boost, so check collision is 2 for 2. I am relatively new to Unreal, so it strikes me as funny that Unreal may have such a collision with EVERY library that has any object that has a method "check" somewhere declared in it's header files. This is probably because a defined macro check is LEAKING. One solution would be to rename macros, but another would be to undefine macros where they shouldn't be applied...

avatar image Matthew J ♦♦ STAFF Mar 29 '16 at 02:01 PM

Thank you for the information. If you do find any other macros that cause conflicts, please let me know and I'll have them added to the report but in the meantime, the feature request is in and waiting to be reviewed.

Have a nice day!

avatar image jeancf Dec 11 '16 at 10:02 AM

I want to weigh in on this request to resolve the macro name collision to allow the use of Boost within UE4.

I have written a driver to interface with a custom controller that requires Boost. After days of work I now get to the point where I want to expose the device in Unreal and I make the shocking realization that because of this issue the integration won't work... You can imagine that I am slightly upset by the situation (to say the least).

At this stage the compiler only throws errors about macro 'check'.

Please, please, please fix this issue.

In the meantime, is there a workaround?

avatar image Matthew J ♦♦ STAFF Dec 12 '16 at 07:01 PM

Hello jeancf,

The feature request for this is still in our system and still open. You can find that feature request here: UE-28766. This change would be a large undertaking and, as mentioned previously, would affect every user who has ever used a check in their own project or in their own engine edit. There is not a workaround that I'm aware of at this time.

avatar image jeancf Dec 14 '16 at 03:02 PM

Obviously I don't like the answer but there is nothing more I can do about it. May I suggest to add a note somewhere in the development sections of the documentation highlighting the incompatibility with these popular libraries? Just to avoid that somebody else wastes precious time writing something that cannot be used in the context of UE4.

avatar image cdglove Feb 25 '17 at 08:06 PM

Why not provide a config macro for backwards compatibility?

  • Redefine all of the macros to something more sensible

  • Fix all of main engine code to use the new macros

  • Supply a config macro, something like

    if SUPPLY_OLDSTYLE_CHECK

    define check NEW_CHECK

    endif

    his allows a clear migration path for any code depending on the old macros if it's really a problem.

Also, I have to agree, it's pretty bad form to use such common names for macros. Haven't we learned from min/max?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Boost is a very ubiquitous library and many libraries and concepts in it makes into the c++ standard. whatever your stance on third party libraries using lower case common words for macro names (check,verify etc) is a very bad practice and I should not need jumble pragmas to undef the stuff..

more ▼

answered Apr 28 '16 at 10:10 PM

avatar image

golgepapaz
6 1 2 4

avatar image SteamyThePunk Dec 14 '16 at 05:06 PM

I agree, Unreal shouldn't be using lower case common words for macro names.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Related: https://answers.unrealengine.com/questions/664876/ue-macros-and-3rd-party-library-conflicts.html

For the record, the usual suspects in my experience have been the check, PI, CONSTEXPR and dynamic_cast macros (yes, they redefine dynamic_cast!):

 #pragma push_macro("CONSTEXPR")
 #undef CONSTEXPR
 #pragma push_macro("dynamic_cast")
 #undef dynamic_cast
 #pragma push_macro("check")
 #undef check
 #pragma push_macro("PI")
 #undef PI
 #include <that-3rd-party-library.hpp>
 #pragma pop_macro("PI")
 #pragma pop_macro("check")
 #pragma pop_macro("dynamic_cast")
 #pragma pop_macro("CONSTEXPR")

more ▼

answered Jul 25 '17 at 08:55 AM

avatar image

hiili
161 6 18 29

avatar image hiili Aug 13 '17 at 08:58 AM

Added #undef CONSTEXPR and #undef dynamic_cast to the list.. Yes, UE indeed does redefine dynamic_cast via a macro. Unbelievable.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

For a workaround, see the "Manual fix" part in this question: https://answers.unrealengine.com/questions/664876/ue-macros-and-3rd-party-library-conflicts.html

In short, you can tweak the UBT-generated response files to allow you to include any 3rd party headers before the UE headers get processed and pollute the macro space:

  1. In Intermediate[...]\YourSourceFile.cpp.obj.response file, remove the line /FI"[...]\Engine\SharedPCH.Engine.h"

  2. Include that file in YourSourceFile.cpp after including your 3rd party library (and before any other UE stuff).

The downside is that you need to re-apply this modification every time after UBT chooses to regenerate the response files.

Of course, this is not how things should be. I sincerely hope that Epic chooses to do something about this.

more ▼

answered Aug 02 '17 at 12:51 PM

avatar image

hiili
161 6 18 29

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I made a small script that generates a pair of headers for undefining and then redefining all macros used by UE.

https://github.com/hiili/UnrealMacroNuke

The releases pages of that repo has pre-generated header pairs for various versions of UE.

more ▼

answered Aug 13 '17 at 12:32 PM

avatar image

hiili
161 6 18 29

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question