ndefined reference to `typeinfo for ncnn::Net' - Serbipunk/notes GitHub Wiki

/usr/bin/ld: CMakeFiles/new_ncnn_forward.dir/net_professional_main.cc.o:(.data.rel.ro._ZTIN6ncnn_M3NetE[_ZTIN6ncnn_M3NetE]+0x10): undefined reference to `typeinfo for ncnn::Net'

solution:

  1. libncnn build

cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/host.gcc.toolchain.cmake -fno-rtti NCNN_DISABLE_RTTI=ON ..

https://github.com/Tencent/ncnn/issues/1376

  1. self lib build

add_definitions(-fno-rtti)

  1. additional: remove any library from this project use c++ typeinfo

(这里需要整理一蛤)

https://en.wikipedia.org/wiki/Run-time_type_information

In C++, RTTI can be used to do safe typecasts, using the dynamic_cast<> operator, 
and to manipulate type information at runtime, using the typeid operator and std::type_info class. 

RTTI is available only for classes that are polymorphic, which means they have at least one virtual method. In practice, this is not a limitation because base classes must have a virtual destructor to allow objects of derived classes to perform proper cleanup if they are deleted from a base pointer.

RTTI is optional with some compilers; the programmer can choose at compile time whether to include the functionality. There may be a resource cost to making RTTI available even if a program does not use it. 

问题原因

  1. 基类的virtual方法在派生类中没有定义

  2. RTTI编译设置错误