Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question "use of dynamic_cast requires -frtti" error occurs when building webgl with native plugin

Discussion in 'WebGL' started by anidiot, Jun 3, 2023.

  1. anidiot

    anidiot

    Joined:
    Sep 19, 2020
    Posts:
    2
    I am building a webgl project with a third party native plugin, and this error occurs:

    ---------------------------------
    D:\Unity\2021.3.13f1c1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\cache\sysroot\include\c++\v1\memory:4597:16: error: use of dynamic_cast requires -frtti
    _Tp* __p = dynamic_cast<_Tp*>(__r.get());

    emcc2: error: 'D:/Unity/2021.3.13f1c1/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Emscripten/llvm\clang++.exe -target wasm32-unknown-emscripten -DEMSCRIPTEN -fno-inline-functions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -D__EMSCRIPTEN_major__=2 -D__EMSCRIPTEN_minor__=0 -D__EMSCRIPTEN_tiny__=19 -D_LIBCPP_ABI_VERSION=2 -Dunix -D__unix -D__unix__ -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL --sysroot=D:\Unity\2021.3.13f1c1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\cache\sysroot -Xclang -iwithsysroot/include\compat -D__webgl__ -Wno-c++11-extensions -Wno-nonportable-include-path -ffunction-sections -fno-unwind-tables -fomit-frame-pointer -fno-threadsafe-statics -std=c++11 -Wno-#warnings -Wswitch -Wno-trigraphs -Wno-tautological-compare -Wno-invalid-offsetof -Wno-implicitly-unsigned-literal -Wno-integer-overflow -Wno-shift-negative-value -Wno-unknown-attributes -Wno-implicit-function-declaration -Wno-null-conversion -Wno-missing-declarations -Wno-unused-value -Wno-pragma-once-outside-header -fvisibility=hidden -fexceptions -fno-rtti -fno-strict-overflow -ffunction-sections -fdata-sections -fmessage-length=0 -pipe -DBASELIB_INLINE_NAMESPACE=il2cpp_baselib -DIL2CPP_MONO_DEBUGGER_DISABLED -DRUNTIME_IL2CPP -DHAVE_BDWGC_GC -DUNITY_WEBGL=1 -DNDEBUG -I. -ID:/Projects/Unity/PuerDemo/Library/Bee/artifacts/WebGL/il2cppOutput/cpp -ID:/Unity/2021.3.13f1c1/Editor/Data/il2cpp/libil2cpp/pch -ID:/Unity/2021.3.13f1c1/Editor/Data/il2cpp/libil2cpp -ID:/Unity/2021.3.13f1c1/Editor/Data/il2cpp/external/baselib/Include -ID:/Unity/2021.3.13f1c1/Editor/Data/il2cpp/external/baselib/Platforms/WebGL/Include -Oz -fcolor-diagnostics -fdiagnostics-absolute-paths -UGC_THREADS -UUSE_MMAP -UUSE_MUNMAP -c -xc++ Assets/Plugins/WebGL/Puerts.cpp -o Library/Bee/artifacts/WebGL/GameAssembly/master_WebGL_wasm/9f4v_Puerts.o' failed (1)

    ---------------------------------

    I noticed that Unity specificly passed the -fno-rtti argument, I have no idea how to customize the arguments, so I located this building script and replaced -fno-rtti with -frtti, and it compiled without error, and the build seemed to be fine as well, running as expected in both PC browser and mobile broswer.

    (I tried using `PlayerSettings.WebGL.emscriptenArgs += " -frtti";`, but it did not work)

    so,
    1. what does -frtti or -fno-rtti do, and is it safe to change it?
    2. how do I pass -frtti to this building script?