Hello,
I am trying to use pybind11 in UnrealeEngine, as a plugin. While I can compile fine a standalone project on Win10 with VS2019 and Python 3.9.0, when compiling inside a UE4 Project I got this error(s):
D:\work_in_progress\UE4\PB11_TEST\Plugins\myPlugin\Source\PyBind11\include\pybind11\detail/common.h(635): error C2988: unrecognizable template declaration/definition
D:\work_in_progress\UE4\PB11_TEST\Plugins\myPlugin\Source\PyBind11\include\pybind11\detail/common.h(637): note: see reference to class template instantiation 'pybind11::detail::is_template_base_of_impl<Base>' being compiled
D:\work_in_progress\UE4\PB11_TEST\Plugins\myPlugin\Source\PyBind11\include\pybind11\detail/common.h(635): error C2059: syntax error: '<end Parse>'
...and more...
it is clearly something related to UE4, I already have spent one day trying to figure out where to search, with no result. Could someone maybe point me in the right direction? This happens even if I only #include "pybind11/pybind11.h"`.
Using Visual Studio 2019 14.28.29334 toolchain and Windows 10.0.17763.0 SDK
Thanks!
Rob
Can you show us a minimal example that fails? It seems your compiler/environment is really messing up things. pybind11 is testsed with VS2019, though.
Can you show us a minimal example that fails? It seems your compiler/environment is really messing up things. pybind11 is testsed with VS2019, though.
Sure. Here is a very basic BP class. the only code added is the #include of pybind11.
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include <pybind11/pybind11.h>
#include "Kismet/BlueprintFunctionLibrary.h"
#include "myBPLibrary.generated.h"
UCLASS()
class UmyBPLibrary : public UBlueprintFunctionLibrary
{
GENERATED_UCLASS_BODY()
//* This is a test function
UFUNCTION(BlueprintCallable)
static float YDebugFunction(float Param);
};
this is the header file of the plugin source code, the .cpp file is
// Copyright Epic Games, Inc. All Rights Reserved.
#include "myBPLibrary.h"
UmyBPLibrary::UmyBPLibrary(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}
float UmyBPLibrary::YmyFunction(float Param)
{
return -1;
}
As you can see, there is nothing but an include (without it the code compiles fine). I agree that is all due to UE4, but I would try to understand and fix it.
I can compile if I use VS2019 as a project by itself. When inserted in UE4, it give a bunch of weird "syntax" errors, starting from what I posted above.
I would investigate more, but at the moment (and with such an obscure error) I'm out of ideas.
-R
Does UE4 know C++11 is required?
Does UE4 know C++11 is required?
Good point. Afaik UE4 uses many c++14 features. I'll check it out.
Yeah, apart from that, I'm just curious in which world parsing already goes wrong :-/ C2059: syntax error: '<end Parse>' seems to be ... weird.
UE4 is not adding a bunch of macros, is it?
UE4 is not adding a bunch of macros, is it?
I think it does. You can see UCLASS(), GENERATED_UCLASS_BODY in the very thin example above, and there is much more.
Here's a related issue: https://github.com/pybind/pybind11/issues/2591
Here's a related issue: #2591
Right! I knew I had seen UE4 before, in an issue.
So UE4 is a big mess, seems to have been the conclusion there? https://github.com/pybind/pybind11/issues/2591#issuecomment-708563385
Yep, let's close this. Thanks anyway!
Just in case someone could find it useful, here is how I solved the problem.
The issue is caused by a UE4 macro: check. To overcome macro pollution in my pybind11 plugin, I added the following code to my header file:
#pragma push_macro("check")
#undef check
#pragma warning (push)
#pragma warning (disable : 4191)
#pragma warning (disable : 4686)
#include "pybind11/pybind11.h"
#pragma warning (pop)
#pragma pop_macro("check")
THIRD_PARTY_INCLUDES_END
As you can see, also a couple of warnings have been silenced, because UE4 enables them (by default in VS2019, they are disabled).
Hmmm, so that's similar but still slightly different from https://github.com/pybind/pybind11/issues/2591#issuecomment-708563385 ?
Well, based on the #2591, I followed the UE4 docs here (Section C++ Warnings and Errors), so added the THIRD_PARTY_INCLUDES_START/END.
Also, undef _check_ is enough for the compile steps to complete successfully (warnings aside).
PS: With "how I solved the problem" I mean "this is my implementation of the solution". I did nothing more than some copy/paste and some test.