我已经下载了最新的Poco库poco-1.7.3.tar。配置了一些属性并安装了。尝试了下面的helloworld示例程序。
#include <iostream>
#include <Poco/Util/Application.h>
class HelloPocoApplication : public Poco::Util::Application
{
protected:
virtual int main(const std::vector<std::string> &args)
{
std::cout << "Hello, POCO C++ Libraries!" << std::endl;
return EXIT_OK;
}
};
POCO_APP_MAIN(HelloPocoApplication);
编译时使用
g++ -I poco-1.7.3/实用程序/包含-I poco-1.7.3/XML/包含-I poco-1.7.3/JSON/包含-I poco-1.7.3/基础/包含-L poco-1.7.3/库/Linux/x86_64 -L poco实用程序-L poco基础-L poco XML-L poco JSON helloworld.cpp -o程序
但它抛出以下错误
/tmp/ccFvl4ll.o: In function `main':
helloworld.cpp:(.text+0x4f): undefined reference to `Poco::Util::Application::init(int, char**)'
helloworld.cpp:(.text+0xd9): undefined reference to `Poco::Logger::log(Poco::Exception const&)'
/tmp/ccFvl4ll.o: In function `Poco::RefCountedObject::release() const':
helloworld.cpp:(.text._ZNK4Poco16RefCountedObject7releaseEv[_ZNK4Poco16RefCountedObject7releaseEv]+0x6e): undefined reference to `Poco::Bugcheck::unexpected(char const*, int)'
/tmp/ccFvl4ll.o: In function `Poco::Util::Application::logger() const':
helloworld.cpp:(.text._ZNK4Poco4Util11Application6loggerEv[_ZNK4Poco4Util11Application6loggerEv]+0x2c): undefined reference to `Poco::Bugcheck::nullPointer(char const*, char const*, int)'
/tmp/ccFvl4ll.o: In function `HelloPocoApplication::HelloPocoApplication()':
helloworld.cpp:(.text._ZN20HelloPocoApplicationC2Ev[_ZN20HelloPocoApplicationC5Ev]+0x14): undefined reference to `Poco::Util::Application::Application()'
/tmp/ccFvl4ll.o:(.gcc_except_table+0x2c): undefined reference to `typeinfo for Poco::Exception'
/tmp/ccFvl4ll.o: In function `Poco::AutoPtr<HelloPocoApplication>::operator->()':
helloworld.cpp:(.text._ZN4Poco7AutoPtrI20HelloPocoApplicationEptEv[_ZN4Poco7AutoPtrI20HelloPocoApplicationEptEv]+0x3a): undefined reference to `Poco::NullPointerException::NullPointerException(int)'
helloworld.cpp:(.text._ZN4Poco7AutoPtrI20HelloPocoApplicationEptEv[_ZN4Poco7AutoPtrI20HelloPocoApplicationEptEv]+0x3f): undefined reference to `Poco::NullPointerException::~NullPointerException()'
helloworld.cpp:(.text._ZN4Poco7AutoPtrI20HelloPocoApplicationEptEv[_ZN4Poco7AutoPtrI20HelloPocoApplicationEptEv]+0x44): undefined reference to `typeinfo for Poco::NullPointerException'
/tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x20): undefined reference to `Poco::Util::Application::name() const'
/tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x28): undefined reference to `Poco::Util::Application::initialize(Poco::Util::Application&)'
/tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x30): undefined reference to `Poco::Util::Application::uninitialize()'
/tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x38): undefined reference to `Poco::Util::Application::reinitialize(Poco::Util::Application&)'
/tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x40): undefined reference to `Poco::Util::Application::defineOptions(Poco::Util::OptionSet&)'
/tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x48): undefined reference to `Poco::Util::Application::run()'
/tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x50): undefined reference to `Poco::Util::Application::handleOption(std::string const&, std::string const&)'
/tmp/ccFvl4ll.o: In function `HelloPocoApplication::~HelloPocoApplication()':
helloworld.cpp:(.text._ZN20HelloPocoApplicationD2Ev[_ZN20HelloPocoApplicationD5Ev]+0x1f): undefined reference to `Poco::Util::Application::~Application()'
/tmp/ccFvl4ll.o:(.rodata._ZTI20HelloPocoApplication[_ZTI20HelloPocoApplication]+0x10): undefined reference to `typeinfo for Poco::Util::Application'
collect2: error: ld returned 1 exit status
你能帮帮我吗?
4条答案
按热度按时间62lalag41#
我设法运行了完全相同的代码,但使用的是Cmake而不是Makefile,它工作了。你只需要根据你的机器更改路径。
下面是我的CMakeLists.txt:
干杯,
z4bn682m2#
检查Poco文档,它似乎应该工作。查看示例here及其makefile,我怀疑您的库的顺序颠倒了。假设路径正确(因为ld没有报告),我会说链接顺序不正确。See here为什么。所以我建议您将命令更改为
第一个月
万一这些例子在将来不知何故超出了范围,这里是复制的代码和makefile。
综上所述,我必须注意你的错误的奇怪之处,特别是在foundation库中发现的Poco::Logger。所以看起来库没有得到链接。我建议两件事:1.检查它是否已损坏。您可以通过清理和重新编译来做到这一点2.尝试在标准路径中安装,以避免链接路径
我知道所有这些都不是确定的(猜测最好),但将有助于为您提供问题所在的提示。
chy5wohz3#
你最初的库链接顺序是正确的,但是你缺少了XML和JSON(Util依赖于这些库)。尽管如此,你得到的链接错误表明你可能缺少了Foundation库或者混合了库的版本。
nx7onnlm4#
尝试这个命令编译。
g++<src_file>.cpp -lPoco基础-lPocoJSON -lPoco实用程序-lPocoJWT -o<binary_name>