2013-01-31 186 views
4

我想在Qt Creator中使用poco库中的一个与poco一起提供的示例,我已经将此工作在Visual Studio 2012中,但是我一直在Qt Creator中出现构建错误。 我有我的lib路径中的.dll和.lib。Qt Creator中的Poco库

这里是我的.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()' 
+2

你在Qtcreator或mingw中使用MSVC2012吗?您不能将使用msvc编译的C++库与mingw一起使用,反之亦然。此外,qmake逻辑看起来有点奇怪:我建议win32 {CONFIG(...){...} else {...}}。 PRE_TARGETDEPS应该是不必要的。 –

回答

1

相同的编译器必须是用于编译以下全部三个:

  1. 波科库

  2. Qt库

  3. 您的应用程序

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