ReactiveX / RxCpp

Reactive Extensions for C++
Apache License 2.0
3.04k stars 394 forks source link

Can't compile. Errors in rx-util and rx-predef #414

Closed Zifkan closed 6 years ago

Zifkan commented 6 years ago

Hi there. Im added files into my game solution(Unreal engine 4 solution) just through menu: add->Existing Item. Then i wrote some simple code for test: auto values1 = rxcpp::observable<>::range(1, 5); values1.subscribe([](int v) { UE_LOG(LogTemp, Warning, v.std::to_string()); });

Added #include "rxcpp/rx-observable.hpp". When i build im getting errors:

image

Whats wrong. Im not very familiar with c++. I used rx in .net and now trying with c++

nikobarli commented 6 years ago

First, you shouldn't write v.std::to_string() but std::to_string(v). Then, the UE_LOG, LogTemp, Warning may also cause errors depending how you declare them.

Debugging a template compile error in C++ is super-hard, especially for people coming from .NET world :) .

When you have a compile error and you couldn't understand it, try to remove the offending codes and re-add them little by little and fix the error when it appears. Also, you'd better see the output window (not the error list window). It will show where in your source code the errors originate (in your case, grep your source cpp "MyProjectCharacter.cpp".

Zifkan commented 6 years ago

Ty for answer, but std::to_string(v) didn't help. Also i removed all test code and still getting error. When i just adding header without code i have this issue

Output: image

nikobarli commented 6 years ago

Did you include rx.hpp ?

#include "rxcpp/rx.hpp"

Zifkan commented 6 years ago

Yes, i included rx.hpp. Also tried other headers like rx-observable.hpp

nikobarli commented 6 years ago

Sorry, don't have any more idea. It may be due to your project settings as well. The warning on _CPPRTI is also suspicious.

You should divide and conquer the problem by yourself. For example, create a new console project, and add the rxcpp code.

kirkshoop commented 6 years ago

hi! would you please send the compiler commandline? you should be able to find it in the project settings. I think that perhaps unreal has disabled some compiler features that rxcpp depends on.

Zifkan commented 6 years ago

Hi. Is this what you asking?

image

kirkshoop commented 6 years ago

This looks like the debugger command line, I would like to see the compiler command line. I see that there is a node for NMake, that may mean that the compiler command line is not visible in the UX. perhaps if there is a build log it will show the command line for cl.exe?

Zifkan commented 6 years ago

Oh. i think im not familiar with what you ask. Can't understand. I look for logs but didn't find something usefull. Can you explain pls more in detail what should i provide and how to do this

kirkshoop commented 6 years ago

I found this question that seems to show the answer: https://answers.unrealengine.com/questions/125830/compiler-options.html

specifically, the answer: "Gleb.Bulgakov Nov 11 '14 at 8:11 AM"

However, I do not think that will help.

This appears to be a bug in unreal:

https://forums.unrealengine.com/development-discussion/c-gameplay-programming/13953-how-to-add-boost-library-to-an-unreal-engine-4-project-visual-studio-2013

03-18-2016, 09:42 AM The answer is that this is a bug. I've made a bug report linked below. The problem is that Unreal uses a lot of macros with commonplace naming, which leads to them conflicting with Boost, and other library's commonplace object names. It's okay for these libraries' objects to have commonplace naming because the objects obey namespace and scope rules, whereas macros don't. This is why Bjarne Stroustrup has been telling C++ programmers to stop using macros and use templates for nearly 2 decades now. (additional link below)

https://answers.unrealengine.com/que...conflicts.html http://www.stroustrup.com/bs_faq2.html#macro

Zifkan commented 6 years ago

Thank you very much. May be ill try to realise this like unreal engine plugin

Zifkan commented 6 years ago

Looks like i resolved problem.

This topic:

https://answers.unrealengine.com/questions/391017/constant-library-conflicts.html

last comment with link to script: https://github.com/hiili/UnrealMacroNuke

This script searching UE headers and redefine Macros. So i have issue with script its didn't generate files. So in resources there are already two generated headers:
"UndefineMacrosUE(version).h" and "RedefineMacrosUE(version).h" (for example: UndefineMacros_UE_4.18.h" and "RedefineMacros_UE_4.18.h )

Then in my solution wich described at the begging i added one header "RedefineRx.h" with simple code as described in instruction

include "UndefineMacros_UE_4.18.h"

include "RxCpp/rx.hpp" // where rx.hpp Rx library file

include "RedefineMacros_UE_4.18.h"

Im not sure is only rx.hpp as main header need redefenition of macros. I tested simple code with UE project auto values1 = rxcpp::observable<>::range(1, 5); values1.subscribe([](int v) { GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Rx value range: %i"), v)); });

And have result in game: image

May be it will help some one

P.S. If im not mistake . It will be great if Rx can be compiled to DLL. It will be way easier way to include this for Unreal engine through UE's Plugin system.

KISLICHOK commented 10 months ago

Hi! Has a better solution been found?) If not, please tell me how to run the script, I will be very grateful.