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即可。
posted @   一沙世界  阅读(140)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· 字符编码:从基础到乱码解决
· Open-Sora 2.0 重磅开源!
历史上的今天:
2017-12-07 gcc cc1: all warnings being treated as errors
2017-12-07 FreeSWITCH取消Digest校验流程
2016-12-07 javax.crypto.BadPaddingException: Given final block not properly padded
点击右上角即可分享
微信分享提示