【问题标题】:C++ Dynamically Linked Libraries loaded at runtime - Poco / qmake在运行时加载的 C++ 动态链接库 - Poco / qmake
【发布时间】:2014-04-07 21:36:58
【问题描述】:

我在使用 Boost 和我的 Mac OS X 时遇到问题。

我使用 Qt Creator 作为 C++ 项目的开发平台,主要是因为 IDE 和qmake

现在我正在开发一个应该是跨平台的 C++ 应用程序,但我不想使用 Qt 框架本身。相反,我使用的是 STD(C++11)PocoBoost

我想要实现的一件事是在运行时加载动态链接库的插件系统。

我看到了一些项目,例如 Boost-extension,它们不再受支持,还有几个其他项目。

现在我正在使用Poco's Shared Libraries 和他们的Class Loader。我正在密切关注演示结束时的教程。不幸的是,我无法让它工作,并且在编译时收到以下错误,ServiceBase 类是我的插件接口。

Undefined symbols for architecture x86_64:
"Poco::SharedLibrary::getSymbol(std::string const&)", referenced from:
      Poco::ClassLoader<ServiceBase>::loadLibrary(std::string const&, std::string const&) in main.o
  "Poco::SharedLibrary::hasSymbol(std::string const&)", referenced from:
      Poco::ClassLoader<ServiceBase>::loadLibrary(std::string const&, std::string const&) in main.o
  "Poco::SharedLibrary::SharedLibrary(std::string const&)", referenced from:
      Poco::ClassLoader<ServiceBase>::loadLibrary(std::string const&, std::string const&) in main.o
  "Poco::SystemException::SystemException(std::string const&, int)", referenced from:
      Poco::MutexImpl::unlockImpl() in main.o
      Poco::MutexImpl::lockImpl() in main.o
  "Poco::LibraryLoadException::LibraryLoadException(std::string const&, std::string const&, int)", referenced from:
      Poco::ClassLoader<ServiceBase>::loadLibrary(std::string const&, std::string const&) in main.o
ld: symbol(s) not found for architecture x86_64

我已经链接了 Poco 库,并且几乎所有内容似乎都已实现。

关于如何解决这个问题的任何建议?

附:我也在寻找实现插件系统的替代方案,可能更强大并且肯定是跨平台的。

【问题讨论】:

    标签: c++ dll runtime poco qmake


    【解决方案1】:

    免责声明。我对这个 Poco 库没有经验。

    如果没有关于您的环境或工具的更多详细信息...我只能提供一些非常笼统的建议:

    我会怎么追:

    1. 找到在哪个库或目标文件中定义了报告为未定义符号的符号。在类 unix 环境中,这可以通过 nm tool 来实现
    2. 验证库或对象是否在正确的体系结构上编译(我看到您使用的是 x86_64)file tool 可能会对您有所帮助
    3. 验证您是否在链接器命令行中引用库(查找 -l 以表示动态或静态库),或者您是否将目标文件或静态库包含在要链接的内容列表中。
    4. 验证您是否引用了正确的库(通过 -L 标志或 LD_LIBRARY_PATH 环境变量(或某些系统中的 LD_LIBRARY_PATH_64,例如用于 64 位构建的 Solaris)

    我知道您说您已链接 Poco 库,但错误显然是缺少符号。要么缺少库,要么您需要调整 -l 标志的顺序以满足依赖关系。 nm 可以帮助您确定引用符号的对象或库(必须先出现)以及定义符号的对象或库(必须稍后出现)。

    很抱歉没有提供更多帮助。

    附:此外,您可能想查看可能相关的Linking error with Poco Net

    对一个详细说明导致链接器错误的不同原因的问题的更多参考:What is an undefined reference/unresolved external symbol error and how do I fix it?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-04
      • 2011-01-04
      • 2013-01-22
      • 2016-11-28
      • 2017-01-12
      • 2016-12-07
      • 2018-05-21
      相关资源
      最近更新 更多