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

來源:互聯網
上載者:User

      之前項目裡使用其它的第三方庫都是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 that qmake searches for libraries and the specific libraries to link against
can be added to the list of values in the LIBS variable. 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 the INCLUDEPATH variable.

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)在INCLUDEPATH variable.後面添加這個引用該庫所需要的標頭檔(例如 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 -lmathLIBS      += -LC:/Qwt-6.0.1/lib -lqwt #必須有 否則報錯 :-1: error: cannot find -lqwt#qtAddLibrary(qwt) #必須有#CONFIG += qwt

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.