我在使用 Boost 和我的 Mac OS X 时遇到问题。
我使用 Qt Creator 作为 C++ 项目的开发平台,主要是因为 IDE 和 qmake
。
现在我正在开发一个应该是跨平台的 C++ 应用程序,但我不想使用 Qt
框架本身。相反,我使用的是 STD 库 (C++11)、Poco
和 Boost
。
我想要实现的其中一件事是一个插件系统,它可以在运行时加载动态链接库。
我看到一些不再受支持的项目,如 Boost-extension
和其他几个项目。
现在我正在使用 Poco's Shared Libraries和他们的类加载器
。我正在密切关注演示文稿末尾的教程。不幸的是,我无法让它工作,并且在编译时收到以下错误,其中 ServiceBase
类是我的插件接口(interface)。
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 库,几乎所有内容似乎都已实现。
关于如何解决这个问题有什么建议吗?
附言我也在寻找实现插件系统的替代方案,可能更强大并且肯定是跨平台的。
最佳答案
免责声明。我没有使用过这个 Poco 库。
没有关于您的环境或工具的更多详细信息...我只能提供一些非常笼统的建议:
我会如何追逐这个:
- 在哪个库或目标文件中找到报告为 undefined symbol 的符号。在类 unix 环境中,这可以通过 nm tool 来实现。
- 验证库或对象是否在正确的体系结构上编译(我看到您使用的是 x86_64)file tool可能对你有帮助
- 确认您在链接器命令行中引用了库(查找 -l 表示动态或静态库),或者您是否在要链接的对象列表中包含目标文件或静态库。
- 验证您指的是正确的库(通过 -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?
关于在运行时加载的 C++ 动态链接库 - Poco/qmake,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22923592/