Can you link Unreal Engine with libraries built with RTTI on Linux?

Unreal Engine has a plugin for integrating with OpenCV. Currently that plugin works on Windows. I’m trying to modify this plugin to work on Linux. I’ve worked through many issues but I have one I can’t resolve.

When I try to build the plugin without modification, I get an error ‘cannot use typeid with -fno-rtti’. The error is from a file ‘any.h’ which is a part of the OpenCV FLANN feature set and appears to have been copied over from boost. To address this, I enable RTTI for the module of the plugin I’m building. Unfortunately, this leads to load time errors like the following.

‘dlopen failed: /home/lvl-dev/Projects/TestOpenCVModules/Plugins/OpenCVLensDistortion/Binaries/Linux/libUE4Editor-OpenCVLensCalibration.so: undefined symbol: _ZTI7UObject ModuleManager: Unable to load module ‘/home/lvl-dev/Projects/TestOpenCVModules/Plugins/OpenCVLensDistortion/Binaries/Linux/libUE4Editor-OpenCVLensCalibration.so’ because the file couldn’t be loaded by the OS.’

As far as I can tell, this is because Unreal builds by default with ‘-fno-rtti’. And now the Unreal objects in my plugin expect RTTI information to be available for the Unreal objects when my libraries are loaded at runtime. I found you can pass ‘RTLD_LAZY’ to’dlopen()’ which I thought would address this but this flag is already being passed when my shared object is loaded.

The next obvious thing is to just build everything with RTTI but I’ve been unable to accomplish this. I’ve seen on some forums that building Unreal with RTTI is possible after version 4.15 or so. However, when I’ve tried to build the engine with RTTI I get errors from attempting to link compiled third party dependencies that are now incompatible with Unreal (WebRTC for example). I’d really rather not work my way through building every Unreal dependency from source myself.

Strangely nothing is done to handle this issue on Windows. It seems the Microsoft linker and runtime handles both RTTI and non-RTTI definitions of the object without issue.

Is there a straight forward way to build and successfully run wtih C++ RTTI enabled?

Is there a way to mix RTTI and non-RTTI objects, as Microsoft seems to do, and suppress the link errors from the runtime?

Is there some solution I’m not considering?

Unfortunately on Linux mixing RTTI and no-RTTI code is very treacherous, see for example this bug: 43105 – Document restrictions on mixing -fno-rtti and -frtti . It is possible to have RTTI enabled in a single module, but then you should be careful to not use engine classes in it - the rest of the (no-RTTI) engine will use that “bridge” to communicate with OpenCV. See OpenEXRWrapper as an example.

Thanks. That clarified the problem a bit for me and I was able to resolve it. I was able to modify the plugin’s includes to leave out the offending ‘typeid()’ call that was coming from boost. It seems so simple now but my C++ knowledge is a bit rusty. I largely got distracted by the fact that this works without issue on the Microsoft stack.

Actually, in my case I had to turn on RTTI returned by GetRTTIFlag in UnrealEngine/Engine/Source/Programs/UnrealBuildTool/Platform/Linux/LinuxToolChain.cs then rebuild UEditor, and set bUseRTTI & bEnableExceptions as true in .Builld.cs file.

That way you enabled RTTI for everything, not just your module.