C++ - Qt Creator 中的 Poco 库

标签 c++ qt poco-libraries

我正在尝试将 Qt Creator 中的 poco 库与 poco 附带的示例之一一起使用,我已经让它在 Visual Studio 2012 中工作,但我在 Qt Creator 中不断遇到构建错误。 我的 lib 路径中有 .dll 和 .lib。

这是我的 .pro 文件

TEMPLATE = app
CONFIG += console
CONFIG -= qt

SOURCES += main.cpp
INCLUDEPATH += C:\Users\justin\Downloads\poco-1.4.6\Net\include
INCLUDEPATH += C:\Users\justin\Downloads\poco-1.4.6\Foundation\include

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/ -lPocoFoundation
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/ -lPocoFoundationd

INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/

win32:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/lib/PocoFoundation.lib
else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/lib/PocoFoundationd.lib

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/ -lPocoNet
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/ -lPocoNetd

INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/

win32:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/lib/PocoNet.lib
else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/lib/PocoNetd.lib

这是 .cpp 文件

#include "Poco/URIStreamOpener.h"
#include "Poco/StreamCopier.h"
#include "Poco/Path.h"
#include "Poco/URI.h"
#include "Poco/Exception.h"
#include "Poco/Net/HTTPStreamFactory.h"
#include "Poco/Net/FTPStreamFactory.h"
#include <memory>
#include <iostream>


using Poco::URIStreamOpener;
using Poco::StreamCopier;
using Poco::Path;
using Poco::URI;
using Poco::Exception;
using Poco::Net::HTTPStreamFactory;
using Poco::Net::FTPStreamFactory;


int main(int argc, char** argv)
{
    HTTPStreamFactory::registerFactory();
    FTPStreamFactory::registerFactory();



    try
    {
        URI uri("http://example.com");
        std::auto_ptr<std::istream> pStr(URIStreamOpener::defaultOpener().open(uri));
        StreamCopier::copyStream(*pStr.get(), std::cout);
    }
    catch (Exception& exc)
    {
        std::cerr << exc.displayText() << std::endl;
        return 1;
    }

    return 0;
}

这些是构建错误:

undefined reference to `Poco::Net::HTTPStreamFactory::registerFactory()'
undefined reference to `Poco::Net::FTPStreamFactory::registerFactory()'
undefined reference to `Poco::URI::URI(char const*)'
undefined reference to `Poco::URIStreamOpener::defaultOpener()'
undefined reference to `Poco::URIStreamOpener::open(Poco::URI const&) const'
undefined reference to `Poco::StreamCopier::copyStream(std::istream&, std::ostream&, unsigned int)'
undefined reference to `Poco::URI::~URI()'
undefined reference to `Poco::URI::~URI()'

最佳答案

必须使用相同的编译器来编译以下所有三个:

  1. Poco 库

  2. Qt 库

  3. 您的申请

我的直觉是你为#3 使用了 MSVC2012,你正确地为 MSVC2012 下载了#2,但是你没有用 MSVC2012 编译#1。

关于C++ - Qt Creator 中的 Poco 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14633070/

相关文章:

c# - 从原始 ECG 信号中提取心率的算法

c++ - C++迭代器:实现迭代器类时出错

c++ - 每个连接的线程与 react 器模式(带有线程池)?

c++ - 如何准确地包含 POCO 库?

makefile - 为什么 `make install` 正在删除 `make` 生成的库文件 *.so ?

c++ - 一个类可以继承自另一个具体化的类模板吗?

c++ - MSVC 接受用 nullptr 初始化的指向 int 的常量指针作为常量表达式

c++ - 为什么python 3.2的Python.h必须和Qt4一起先包含进来

c++ - 为什么 QSharedPointer<T>::create 调用不完整对象的析构函数?

c++ - 信号:QStandarditemmodel::datachanged(...) 在使用 QStandarditemmodel::setData(...) 时不发出角色)