zoukankan      html  css  js  c++  java
  • undefined reference to `FilterRegistry::RegisterFilter(std::shared_ptr<Filter>&)'

    记一次undefined reference排查

    一、背景:

    1. 编译模块A,三部曲通过
    2. 编译模块B(依赖模块A),报错:
      /usr/bin/ld: OrkAudio.o: in function Transcode(CStdStr<char>&):
      /home/lings/GitSpace/oreka/orkaudio/OrkAudio.cpp:173:
      undefined reference to FilterRegistry::RegisterFilter(std::shared_ptr<Filter>&)
      /usr/bin/ld: /home/lings/GitSpace/oreka/orkaudio/OrkAudio.cpp:175: undefined reference to FilterRegistry::RegisterFilter(std::shared_ptr<Filter>&)
      /usr/bin/ld: /home/lings/GitSpace/oreka/orkaudio/OrkAudio.cpp:177:
      undefined reference to FilterRegistry::RegisterFilter(std::shared_ptr<Filter>&)
      /usr/bin/ld: /home/lings/GitSpace/oreka/orkaudio/OrkAudio.cpp:179: undefined reference to FilterRegistry::RegisterFilter(std::shared_ptr<Filter>&)
      /usr/bin/ld: /home/lings/GitSpace/oreka/orkaudio/OrkAudio.cpp:181: undefined reference to FilterRegistry::RegisterFilter(std::shared_ptr<Filter>&)
      /usr/bin/ld: OrkAudio.o:/home/lings/GitSpace/oreka/orkaudio/OrkAudio.cpp:183:

    二、排查

    1. 查看A模块里面的方法:
      nm /usr/lib/liborkbase.so |grep FilterRegistry
    2. 得到的结果如下:
      000000000004ecd0 T _ZN14FilterRegistry14RegisterFilterERN5boost10shared_ptrI6FilterEE
    3. 乍一看没问题,仔细看入参的指针类型不一样!
    4. 模块A里的是boost::shared_ptr
    5. 模块B里的入参是std::shared_ptr

    三、解决

    1. 源代码里确实允许使用两种
      #ifdef SUPPORTS_CPP11
      #include <memory>
      namespace oreka {
      using std::shared_ptr;
      using std::make_shared;
      using std::weak_ptr;
      };
      #else
      #include <boost/shared_ptr.hpp>
      #include <boost/make_shared.hpp>
      #include <boost/weak_ptr.hpp>
      namespace oreka {
      using boost::shared_ptr;
      using boost::make_shared;
      using boost::weak_ptr;
      };
      #endif
    2. 而B模块编译的时候Makefile文件中指定了CPP11
      CXXFLAGS = -std=c++11 -g -O2 -fno-inline-functions -std=c++11 -DSUPPORTS_CPP11 -fPIC
    3. 去掉B模块指定的-DSUPPORTS_CPP11即可。
    上善若水,水利万物而不争。
  • 相关阅读:
    多线程自动化运维linux的尝试 优化二
    多线程自动化运维linux的尝试 优化一
    多线程自动化运维linux的尝试
    mysql root 没有任何权限
    oracle hint 知多少
    pandas 实战笔记
    ICM issue IcmPlAllocBuf: MpiGetOutbuf failed (rc = 14 (MPI_ESTALE: outdated MPI handle))
    利用python在Oracle数据库中生成密码字典库
    nginx 配置的一些参数
    nginx四层代理
  • 原文地址:https://www.cnblogs.com/yoyotl/p/15655948.html
Copyright © 2011-2022 走看看