heroiclabs / nakama-unreal

Unreal client for Nakama server.
Apache License 2.0
205 stars 62 forks source link

Unreal - NAKAMA_NAMESPACE often causing "ambiguous symbol" compilation errors #46

Closed DeoVolenteGames closed 7 months ago

DeoVolenteGames commented 3 years ago

I'm back to revisiting my plan for a simple BP API plugin for Nakama, now that I'm able to open source it. However, the recent updates are making this almost impossible, and I'm not sure why.

My issue seems to be that placing using namespace NAKAMA_NAMESPACE; in a header can cause compilation errors, even if #include "nakama-cpp-c-wrapper/NakamaWrapperImpl.h" is in an unrelated .cpp file. If they were in the same file or a header and accompanying source file I'd understand, but these are unrelated files. However, I'm having a hard time reproducing this in a new project so I'm not sure yet if this is a Nakama problem or a me problem. All I know is that if I create a new file in my problem project which includes "NakamaUnreal.h" and has using namespace NAKAMA_NAMESPACE; it won't compile.

If you'd like I can supply the project that's causing me issues; it might be something silly and obvious but I can't figure out what I'm doing wrong because the error messages are so unhelpful.

NStringMap.h(32): [C2872] 'NStringMap': ambiguous symbol
NStringMap.h(25): [C2872] could be 'NStringMap_ *NStringMap'
NTypes.h(58): [C2872] or       'NakamaWrapper::NStringMap'
NStringMap.h(39): [C2872] 'NStringMap': ambiguous symbol
NStringMap.h(25): [C2872] could be 'NStringMap_ *NStringMap'
NTypes.h(58): [C2872] or       'NakamaWrapper::NStringMap'
... similar stuff repeated

If you can provide some guidance I'd really appreciate it.

DeoVolenteGames commented 3 years ago

I came back to this and tried to find a solution but now I'm totally lost. I have using namespace NAKAMA_NAMESPACE; in one .cpp file and #include "nakama-cpp-c-wrapper/NakamaWrapperImpl.h" in a completely unrelated .cpp file and it causes ambiguous symbol errors. I don't know what UE4 does while compiling but something's messed up. I basically have to drop using and use NAKAMA_NAMESPACE:: for everything instead I think. I tried doing a rebuild, I tried cleaning out intermediate files, etc. It's some build step that somehow causes this. It's quite a pain.

I'm following the instructions accurately AFAIK but the update has made this plugin less easy to use. It would have been nice if the namespace was called NAKAMA instead of NAKAMA_NAMESPACE at least.

marot commented 3 years ago

@DeoVolenteGames The problem might be related to the unity build system that Unreal Engine is using, see https://docs.unrealengine.com/en-US/ProductionPipelines/DevelopmentSetup/CodingStandard/index.html#namespaces

Unity builds will put all your code into a single file and because using namespace NAKAMA_NAMESPACE is global, it will cause problems.

Note that NAKAMA_NAMESPACE is a macro that either is defined as Nakama or NakamaWrapper depending on what header files you include. If you include nakama-cpp headers directly, it will resolve to Nakama but if you include NakamaUnreal.h first, it will resolve to NakamaWrapper.

For the usage of nakama-unreal the name NakamaWrapper should be used. So instead of using NAKAMA_NAMESPACE:: you could use NakamaWrapper:: directly.

I hope this helps - if not, could you share a reproduceable repo?

DeoVolenteGames commented 3 years ago

That's a good catch, thank you very much! That makes a lot of sense and answers all my questions.

If this is the case though, I think the documentation for nakama-unreal should probably be updated to let people know that using namespace NAKAMA_NAMESPACE shouldn't be used outside of a function or namespace scope. Thanks again for your help!

brendenfrank commented 3 years ago

Agreed, I encountered the same pitfalls and was a bit lost until I found this thread.