1. 程式人生 > >QtCreator的中如何使用第三方依賴庫

QtCreator的中如何使用第三方依賴庫

      之前專案裡使用其它的第三方庫都是leader或同事給配置好的,從沒操心這回事,真是慚愧,哭。今天同學給我發來一個工程,需用使用到Qt庫和Qwt庫,用QtCreator開啟編譯,提示找不到Qwt庫裡的標頭檔案,於是試著配置一下,居然折騰了許久還沒執行起來。後來看了一下Qt的qmake文件,才得以搞定。qmake 的說明文件裡有關於宣告使用其它庫的說明:

Declaring Other Libraries

If you are using other libraries in your project in addition to those supplied with Qt, you need to specify them in your project file.

The paths thatqmakesearches for libraries and the specific libraries to link against can be added to the list of values in theLIBSvariable. The paths to the libraries themselves can be given, or the familiar Unix-style notation for specifying libraries and paths can be used if preferred.

For example, the following lines show how a library can be specified:

 LIBS += -L/usr/local/lib -lmath

The paths containing header files can also be specified in a similar way using theINCLUDEPATHvariable.

For example, it is possible to add several paths to be searched for header files:

 INCLUDEPATH = c:/msdev/include d:/stl/include

    如果電腦上已經安裝了Qt 和Qwt的環境,那麼對於一個需要使用Qwt的程式來說,只需要在其工程檔案中新增如下配置:

(假設你的Qwt安裝目錄為 C:/Qwt-6.0.1 )

1)在LIBS 變數後面新增連結這個庫的路徑(例如-LC:/Qwt-6.0.1/lib)和名稱(例如 -lqwt, 也可以用 qtAddLibrary(qwt) 新增動態庫

2)在INCLUDEPATHvariable.後面新增這個引用該庫所需要的標頭檔案(例如 C:/Qwt-6.0.1/include

#include( $${PWD}/../examples.pri )
#include( ../3rdparty/qwt/qwtplot.pri )
#include( C:/Qwt-6.0.1/features/qwtconfig.pri )
INCLUDEPATH += C:/Qwt-6.0.1/include #必須有
#DEPENDPATH  += C:/Qwt-6.0.1/lib
#LIBS += -L/usr/local/lib -lmath
LIBS      += -LC:/Qwt-6.0.1/lib -lqwt #必須有 否則報錯 :-1: error: cannot find -lqwt
#qtAddLibrary(qwt) #必須有

#CONFIG += qwt