[英]How do I go about adding a third party library to QtCreator?
我正在嘗試將OpenXLSX添加到我的QtCreator項目中,但是按照本指南的操作,我似乎無法讓QtCreator找到頭文件。
QtCreator手冊中提到了該庫未使用的.lib文件,因此我對該指南有些迷惑。 我四處OpenXLSX/@library/@openxlsx/interfaces/c++/
,嘗試將來自OpenXLSX/@library/@openxlsx/interfaces/c++/
標頭和源添加到項目樹中的標頭和源目錄中。 但是我仍然得到
exceltest.cpp:3: error: 'OpenXLSX.h' file not found
第3行是
#include "OpenXLSX.h"
我也嘗試過
#include "3rdparty/OpenXLSX/@library/@openxlsx/interfaces/c++/headers/OpenXLSX.h"
3rdparty目錄與exceltest.pro位於同一位置
我也嘗試過使用尖括號。
我不需要OpenXLSX的任何高級功能,只需在我為.xlsx或.xls指定的單元格中讀取和寫入值即可。 我也不喜歡使用OpenXLSX的想法,因此,如果有人知道excel,那么任何可以更好地工作的庫都可以接受。
編輯:因此,在我將標題和源添加到項目樹之后,我的exceltest.pro看起來像這樣 。 我試圖把這條線
#include "3rdparty/OpenXLSX/@library/@openxlsx/interfaces/c++/headers/OpenXLSX.h"
進入exceltest.h而不是exceltest.cpp,我得到了不同的錯誤。 QtCreator似乎找到了庫文件,但是庫有問題嗎? 這些是錯誤:
In file included from J:/George/Coding/Qt/Test/exceltest/3rdparty/OpenXLSX/@library/@openxlsx/interfaces/c++/headers/XLCell.h:49:0,
from ..\exceltest\3rdparty\OpenXLSX\@library\@openxlsx\interfaces\c++\sources\XLCell.cpp:5:
J:/George/Coding/Qt/Test/exceltest/3rdparty/OpenXLSX/@library/@openxlsx/interfaces/c++/headers/XLDefinitions.h:57:35: warning: multi-character character constant [-Wmultichar]
constexpr uint32_t maxRows = 1'048'576;
^~~~~
J:/George/Coding/Qt/Test/exceltest/3rdparty/OpenXLSX/@library/@openxlsx/interfaces/c++/headers/XLDefinitions.h:59:36: warning: missing terminating ' character
constexpr uint16_t maxCols = 16'384;
^
J:/George/Coding/Qt/Test/exceltest/3rdparty/OpenXLSX/@library/@openxlsx/interfaces/c++/headers/XLDefinitions.h:59:36: error: missing terminating ' character
constexpr uint16_t maxCols = 16'384;
^~~~~
..\exceltest\3rdparty\OpenXLSX\@library\@openxlsx\interfaces\c++\sources\XLCellRange.cpp:5:10: fatal error: XLCellRange.h: No such file or directory
#include <XLCellRange.h>
^~~~~~~~~~~~~~~
compilation terminated.
..\exceltest\3rdparty\OpenXLSX\@library\@openxlsx\interfaces\c++\sources\XLCellReference.cpp:5:10: fatal error: XLCellReference.h: No such file or directory
#include <XLCellReference.h>
^~~~~~~~~~~~~~~~~~~
首先,您必須構建OpenXLSX項目才能獲取該庫。 該項目使用cmake進行生成。 您需要首先生成工作區:
列出所有可用的發電機
cmake --help
選擇您要使用的那個,然后:
cmake . -G "Your generator"
根據生成器構建項目。 庫和頭文件將復制到安裝目錄中。
在您的.pro文件中,添加以下行:
INCLUDEPATH += /path/to/OpenXLSX/include
LIBS += -L/path/to/OpenXLSX/lib -lopenxlsx.lib
第一個允許您包括OpenXLXS標頭。 鏈接器將使用第二行將庫鏈接到您的應用程序。
如果要在Windows或Linux上構建項目,則可能需要使用其他版本的庫。 您可以使用以下語法:
# On Windows in release mode
win32:CONFIG(release, debug|release): LIBS += -L/path/to/OpenXLSX/lib -lopenxlsx.dll
#On Windows debug mode
else:win32:CONFIG(debug, debug|release): LIBS += -L/path/to/OpenXLSX/lib -lopenxlsx_debug.dll
#On Linux debug and release
else:unix: LIBS += -L/path/to/OpenXLSX/lib -lopenxlsx.so
在Qt Creator中,如果右鍵單擊項目,則可以使用專用向導添加庫(上下文菜單中的“ Add Library
選項)。 它將在* .pro中添加您需要的所有內容
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.