[英]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.