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即可。
    上善若水,水利万物而不争。
  • 相关阅读:
    解决Jenkins上git出现的“ERROR: Error fetching remote repo 'origin'”问题
    安装loadround时WebTours打不开的解决办法
    使用的postman心得
    IO流
    正则表达式用例
    一个纸杯该如何测试
    https与http的区别
    IO流操作之字符输入输出流简单操作
    手机APP测试获取上下文
    Appium第二天
  • 原文地址:https://www.cnblogs.com/yoyotl/p/15655948.html
Copyright © 2011-2022 走看看