2017-03-20 54 views

回答

0

將庫添加到Qt項目實際上很簡單。在您的QMAKE .pro文件,你需要以下條件:

# This is the search location for the compiler to look for headers that accompany your library. 
# For system libraries that typically resides under **/usr/include** or **/usr/local/include** if you used `make install`. 
INCLUDEPATH+="/path/of/headers/for/library" 

# This is the search location for the compiler/linker to look for the library itself. 
# For system libraries this is usually somewhere under **/usr/lib** or **/usr/local/lib** 
LIBS+= -L/path/of/library/itself 

# This is the name of the library to include at link time 
# without the **lib** prefix and the **.so**/**.a**/**.lib**/**.dll** extension. 
LIBS+= -lMyLibraryName 

# This is the full path of the library file itself 
# *including* the aforementioned **lib** prefix and the **.so**/**.a**/**.lib**/**.dll** extension. 
# This is used by qmake to look for changes to the library at build time, 
# to make sure it is re-linked on change and other dependency related stuff 
PRE_TARGETDEPS += /path/and/filename/of/library/itself/libMyLibraryName.lib 

提示:所有的路徑,除非它們被指定爲絕對路徑(以「/」)將是相對build目錄。這可能是項目目錄,但在shadow builds的情況下,它將是陰影構建目錄。作爲提示,簡單地將以下內容添加到相對路徑中,以使它們相對於項目目錄:$$_PRO_FILE_PWD_/因此,例如,如果您的lib駐留在/my/qt/project/libs/mylib中,則可以使用$$_PRO_FILE_PWD_/libs/mylib代替$$_PRO_FILE_PWD_/libs/mylib來使項目具有彈性。請注意,「項目目錄」是qmake .pro文件的位置。